2

I always thought we can't access JS Object Literal value in same object as stated here,

Access JavaScript Object Literal value in same object

But I came across this library which is doing exactly opposite. It most likely be something I am missing but I can't figure it out.

Here is how library doing it, http://image.prntscr.com/image/2cd771f00f604b51be4b7befca49709e.png

And it's not using "this" as well to access "defaults"

Edit

Seems like latest revision of library doesn't has the same code. But I am looking at exercise files of this course,

https://app.pluralsight.com/library/courses/typescript/table-of-contents

Community
  • 1
  • 1
Mathematics
  • 7,314
  • 25
  • 77
  • 152

1 Answers1

1

It seems you're confused between object properties and variable.

Default is variable not object property. enter image description here

For more detail, let's see lexical scoping example in MDN

The getOptions function has no local variables of its own. However, because inner functions have access to the variables of outer functions, getOptions() can access the variable default declared in the parent function

function init() {
  var name = 'Mozilla'; // name is a local variable created by init
  function displayName() { // displayName() is the inner function, a closure
    alert(name); // use variable declared in the parent function    
  }
  displayName();    
}
init();
taile
  • 2,738
  • 17
  • 29
  • Tai, in your example you are not self accessing variable or property like it's happening in the example, if I make sense ? – Mathematics May 05 '17 at 11:33
  • @mathematics did you see my attached pic. The var keyword before defaults is the point you should notice.. – taile May 05 '17 at 13:00