js 原型链总结

举个例子

function Test() {

this.name = "吕布";
this.age = "35";
this.skill_1 = function () {
console.log(2)
};
this.skill_2 = function () {
console.log(3)
}
}

Test.prototype.skillPrototype1 = function () {
console.log('skillPrototype1')
};
Test.prototype.skillPrototype2 = function () {
console.log('skillPrototype2')
};
Test.prototype.haha = "1111";

var test = new Test();

console.log(test);

//继承
function Data() {
Test.apply(this)
}
Data.prototype = Test.prototype;

var newData = new Data();
console.log(newData);

// prototype 构造器原型上定义方法和属性
// __proto__ 指向构造函数原型上
// constructor 指向构造器
//通过这样一层一层的指向最顶端Object 构成原型链
posted @ 2019-05-09 12:05  zou1234  阅读(292)  评论(0编辑  收藏  举报