Created
June 17, 2016 14:55
-
-
Save jsatt/51d872fd716e9264953a754d6ff6186f to your computer and use it in GitHub Desktop.
Understanding js prototyping
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
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