类函数,也叫构造函数,在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);