Skip to content

Instantly share code, notes, and snippets.

@wolmhp
Last active December 10, 2015 20:58
Show Gist options
  • Save wolmhp/4491753 to your computer and use it in GitHub Desktop.
Save wolmhp/4491753 to your computer and use it in GitHub Desktop.
JavaScript 简单继承
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