Skip to main content

Forums

This topic contains 2 replies, has 3 voices, and was last updated by  Xiija 1 year ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #267389

    Pranab
    Participant

    I have a function,

    function pranab(){
      return this;
    }
    var obj = pranab;
    console.log(obj()); //Window object
    

    but if i create a object and assign this function inside this object, the,

    var obj = {
      name: pranab
    }
    console.log(obj.name());//the object itself
    

    So, here what’s the deal with variable?Why variable not return the variable itself as a result.

    #267396

    Shikkediel
    Participant

    I’m seeing it return the object property (it’s not a variable) itself.

    codepen.io/gvjOgL

    Edit – hmm… in Opera, not Firefox. That is odd. But from my limited knowledge about closures I would expect it to return the parent object anyway.

    #267600

    Xiija
    Participant

    not sure what you are tryin to do?
    anyhoo….

    See Codepen

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

icon-link icon-logo-star icon-search icon-star