Last active
February 18, 2016 23:57
-
-
Save karenpeng/5c0e7a73b9bb02c8a13b to your computer and use it in GitHub Desktop.
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
function a () { | |
var value = 1; | |
return{ | |
get: function(){ | |
return value | |
}, | |
set: function(n){ | |
value = n | |
return value | |
} | |
} | |
} | |
var aa = a() | |
console.log(aa.get()) | |
console.log(aa.set(2)) | |
var b = { | |
value: 1, | |
get: function(){ | |
return this.value | |
}, | |
set: function(n){ | |
this.value = n | |
return this.value | |
} | |
} | |
console.log(b.get()) | |
console.log(b.set(3)) | |
var test = b.get | |
console.log(test())//throw an error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment