Created
July 7, 2014 05:40
-
-
Save hailiang-wang/19a172a35fa59932cf64 to your computer and use it in GitHub Desktop.
the quickest way to inherit methods in javascript via prototype
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
// define a parent | |
var s = { | |
print: function(x) { | |
console.log(x); | |
} | |
} | |
s.print('Hello World'); | |
// now define a heir | |
var m = {}; | |
// I think this is the quickest way to set s as ancestor | |
m.prototype = s; | |
// but it is not | |
m.print('foo'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some questions about javascript as a lang.