Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js object

'use strict';

var obj = {
  a: 10
  b:20
};

Object.defineProperty(obj, 'b', {
  get: () => {
    console.log(this.a, typeof this.a, this); // undefined 'undefined' Window {...} (or the global object)
    return this.a + 10; // represents global object 'Window', therefore 'this.a' returns 'undefined'
  }
});
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #js #object
ADD COMMENT
Topic
Name
5+2 =