3:jquery原生链的构造

类函数,也叫构造函数,在java中,constructor为构造函数,类被实例化的时候,就直接执行的一个函数

function init() {
   console.log(1);
}

console.log(init.prototype);//输出一个对象
//constructor构造函数 init()
//prototype 对象(__proto__)

函数的原型 里面的构造函数指向自身 自己添加的方法叫原型方法

init.prototype={
    constructor:init,
    method:function(){
        console.log("原型里面自己添加的方法");
    }
}
var  _init=new init();
console.log(_init);
_init.method();

原型链 只有在继承之后 才会产生原型链

//学生函数
function student(){

}
//中国人函数
function china(){
    this.color=function(){
        console.log("中国人");
    }
}
china.prototype={
    constructor:china,
    color:function(){
        console.log("中国人的肤色是黄色");
    }
}
//人类的函数
function people(){
    this.allpeople=function(){
        console.log("大家");
    }
}
people.prototype={
    constructor:people,
    allpeople:function(){
        console.log("大家都是人类啊");
    }
}
//原生链的构造
student.prototype=new china();
china.prototype.__proto__=new people();
var s=new student;
console.log(s);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值