js的原型链
创始人
2025-01-15 06:05:11
0

原型链:

        1.如何构成原型链?

        2.原型链上属性的增删改查。

        3.绝大多数对象的最终都会继承自Object.prototype    (var obj = Object.create(null或者undefined)没有原型)。

        4.Object.create(原型)。

构成原型链和操作原型链属性:
//最顶的原型是Object.prototype Grand.prototype.__proto__ = Object.prototype; Grand.prototype.lastName = "Deng"; function Grand(){    };  var grand = new Grand();  Father.prototype = grand; function Father(){     this.name = "xuming";     this.fortune = {         card1 : "visa",     };     this.num = 100; };  var father = new Father();  Son.prototype = father; function Son(){     this.hobbit = "smoke"; };  var son = new Son();  //操作原型链上的属性,son会在自身生成一个属性 son.num++; // ---> son.num = son.num + 1; console.log(father.num); //100 console.log(son.num); //101  //操作原型链上的对象中的属性,son不会生成属性 son.fortune.card2 = 'master' console.log(son.fortune); //{card1 : 'visa',card2 : 'master'} console.log(father.fortune); //{card1 : 'visa',card2 : 'master'} 
原型中this的指向:
//a.sayName() sayName里面的this指向是,谁调用的这个方法,this就是指向谁 Person.prototype = {     name : "a",     sayName : function(){         console.log(this.name);     }     }  function Person(){     this.name = "b"; }          var person = new Person(); person.sayName(); //b person.__proto__.sayName(); //a
Object.create(原型):

对象形式:

var obj = {name : "sunny"}; var obj1 = Object.create(obj);  console.log(obj1.name); //sunny

函数形式:

Person.prototype.name = "sunny"; function Person(){  } var person = Object.create(Person.prototype); var person1 = new Person();  console.log(person.__proto__.name); //sunny console.log(person1.__proto__.name); //sunny

相关内容

热门资讯

透视数据!智星德州有脚本吗,w... 《透视数据!智星德州有脚本吗,wepoker游戏下载(详细辅助解密教程)》 智星德州有脚本吗软件透明...
wpk辅助工具下载!拱趴大菠萝... wpk辅助工具下载!拱趴大菠萝开挂方法,wepoker底牌透视脚本下载(详细辅助解密教程);wpk辅...
辅助透视!wepoker轻量版... 辅助透视!wepoker轻量版透视,小程序边锋辅助(原来真的是有挂)1、小程序边锋辅助系统规律教程、...
透视了解“aapoker透视软... 透视了解“aapoker透视软件”真是真的是有挂(辅助挂)详细辅助详细教程透视了解“aapoker透...
透视ai代打!hhpoker万... 透视ai代打!hhpoker万能辅助器,聚星ai辅助工具激活码(详细辅助科技教程)1、不需要AI权限...
wepoker透视脚本免费下载... wepoker透视脚本免费下载!wepoker透视最简单三个步骤,wpk透视脚本链接(详细辅助202...
透视神器“wepoker免费透... 透视神器“wepoker免费透视脚本”果然存在有挂(辅助挂)详细辅助攻略教程1)辅助挂:进一步探索辅...
透视美元局!wepoker怎么... 透视美元局!wepoker怎么挂底牌,胡乐安庆辅助工具(真是是真的有挂)胡乐安庆辅助工具软件透明挂微...
透视辅助!wepoker透视,... 透视辅助!wepoker透视,德州之星扫描器(详细辅助教你攻略)关于德州之星扫描器机制的,其中提到了...
wepoker透视脚本安卓!p... wepoker透视脚本安卓!pokermaster脚本,wepoker底牌透视脚本http(详细辅助...