Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript This value not returned the variable itself in JS

  • This topic is empty.
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)
  • The forum ‘JavaScript’ is closed to new topics and replies.