标签:
一.prototype(原型)
1.
function Person (name) {
this.name = name;
}
function Star (name) {
}
Star.prototype = new Person("鹿晗");
var who = new Star();
console.log(who.name);
2.
function Person (name) {}
Person.prototype.name = "鹿晗";
function Star (name) {}
Star.prototype = Person.prototype;
var who = new Star();
console.log(who.name);
二.call(一个字符)
function Person (name) {
this.name = name;
}
function Star (name) {
Person.call(this,name);
}
var who = new Star("鹿晗");
console.log(who.name);
三.apply(一个数组)
function Person (name) {
this.name = name;
}
function Star (name) {
Person.apply(this,[name]);
}
var who = new Star("鹿晗");
console.log(who.name);
标签:
原文地址:http://www.cnblogs.com/chenhongcai/p/5781837.html