Created
April 19, 2011 13:38
-
-
Save shinout/927741 to your computer and use it in GitHub Desktop.
this.hoge; // <- getter ? setter?
set: function(val) {this._piyo = val} // is this piyo affected to original object?
This file contains 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 characters
/* see if just "obj.hoge" is setter or getter */ | |
var obj = {}; | |
Object.defineProperty(obj, 'hoge', { | |
get: function(){console.log("get")}, | |
set: function(){console.log("set")} | |
}); | |
obj.hoge; | |
/* see if this._hoge is readable / writable */ | |
var fuga = {}; | |
Object.defineProperty(obj, 'piyo', { | |
get: function(){return this._piyo}, | |
set: function(val){this._piyo = val} // this._piyo is hidden!!! | |
}); | |
console.log(fuga.piyo); | |
console.log(fuga._piyo); | |
console.log(fuga); | |
fuga.piyo = "shinout"; | |
console.log(fuga.piyo); | |
console.log(fuga._piyo); | |
console.log(fuga); | |
fuga._piyo = "fu-ga"; | |
console.log(fuga.piyo); | |
console.log(fuga._piyo); | |
console.log(fuga); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment