Created
August 13, 2017 12:58
-
-
Save oriSomething/b30d9d4135a6673087a31c3404cf7b3c to your computer and use it in GitHub Desktop.
Revisions
-
oriSomething created this gist
Aug 13, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ var obj = { _fooValue: 1, _fooGetterShouldReturnThis: false, get foo() { var value = this._fooGetterShouldReturnThis ? this : this._fooValue; this._fooGetterShouldReturnThis = false; return value; }, set foo(value) { this._fooGetterShouldReturnThis = true; this._fooValue = value + 1; } } var foo = (obj.foo = 10); console.log(foo); // Output `10` instead of `Object { ··· }` or even `11` console.log(obj.foo); // Output `Object { ··· }` which is `obj` console.log(obj.foo); // Output `11` which is `obj._fooValue`