Skip to content

Instantly share code, notes, and snippets.

@jsatt
Created June 17, 2016 14:55
Show Gist options
  • Save jsatt/51d872fd716e9264953a754d6ff6186f to your computer and use it in GitHub Desktop.
Save jsatt/51d872fd716e9264953a754d6ff6186f to your computer and use it in GitHub Desktop.
Understanding js prototyping
res = function(){
mr = function(obj){
this.testing = obj
// or _.extend(this, obj) or Object.assign(this, obj) to extend this
};
mr.prototype.tester = function(){
return this.testing.test
};
return mr
}
m = res() // mr
r = new m({test: 123}) // Object { testing: Object { test: 123 } }
r.tester() // 123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment