Last active
December 10, 2015 20:58
-
-
Save wolmhp/4491753 to your computer and use it in GitHub Desktop.
JavaScript 简单继承
This file contains hidden or 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 car(name) { | |
| this.name = name; | |
| } | |
| car.prototype.getName = function() { | |
| alert(this.name); | |
| } | |
| function benz(name) { | |
| car.call(this,name); | |
| } | |
| benz.prototype = new car(); | |
| var benz1 = new benz('benz'); | |
| benz1.getName(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment