js 原型链总结

Posted zou1234

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 构成原型链

以上是关于js 原型链总结的主要内容,如果未能解决你的问题,请参考以下文章