Skip to content

Instantly share code, notes, and snippets.

@karenpeng
Last active February 18, 2016 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karenpeng/5c0e7a73b9bb02c8a13b to your computer and use it in GitHub Desktop.
Save karenpeng/5c0e7a73b9bb02c8a13b to your computer and use it in GitHub Desktop.
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