Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8992447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:57:25+00:00 2026-06-15T22:57:25+00:00

if I have this json structure: var j = { param1: ‘hello’, param2: ‘world’,

  • 0

if I have this json structure:

var j = {
    param1: 'hello',
    param2: 'world',
    func:   function() {
        console.log(this.param1 + ' ' + this.param2);
    }
};

this in func is undefined. How to access self in this json object? Thanks

EDIT:

I’m trying it with:

j.func();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:57:26+00:00Added an answer on June 15, 2026 at 10:57 pm

    this is determined by how a function is called. To answer your question, we would need to see how you are called func().

    If you call:

    j.func()
    

    then, this inside of func will be set to j.

    If you call func() directly (which is what happens if you pass j.func as a callback which is then called directly by some other function), then this will probably be set to either window or undefined depending upon whether you are in strict mode or not. For example:

    function callme(callback) {
        // the context of `j` will be lost here and 
        // this will just call func() directly without setting this to j
        callback();
    }
    
    callme(j.func);
    

    this can also be set explicitly by the caller by using j.func.apply() or j.func.call() which allow the caller to specify the desired value of this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this structure: MyApp.User = function() { var self = this; self.ID =
I have some data and need to create a json file with this structure
i have this JSON: var projects_array = new Array( {name:myName1, id:myid1, index:1}, {name:myName2, id:myid2,
i have this json structure and I made it into an array. I was
I have this XML structure that I wish to construct in JSON format using
I created a json with this structure var data = { people: [ {
I have this structure: HTML part: <table id=table_div class=table table-striped table-condensed><tbody></tbody></table> JS part: var
I have some json in this structure: {data:{1:file1.gif,2:file2.jpg}} // ... etc I am trying
i have this JSON object: {error:null, result:[{id:1234567890, count:1, recipients: [u3848, u8958, u7477474 ], dateCreated:2012-06-13T09:13:45.989Z
I have this JSON http://www.progmic.com/ielts/retrive.php that I need to parse. When I do it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.