javascript - Self-references in object literal declarations -
is there way following work in javascript?
var foo = {     a: 5,     b: 6,     c: this.a + this.b  // doesn't work };   in current form, code throws reference error since this doesn't refer foo. is there way have values in object literal's properties depend on other properties declared earlier?
well, thing can tell getters:
var foo = {   a: 5,   b: 6,   c () {     return this.a + this.b;   } };  foo.c; // 11   this syntactic extension introduced ecmascript 5th edition specification, syntax supported modern browsers (including ie9).
Comments
Post a Comment