1.构造一个Person对象(相当于Java中的参数化构造函数)functionperson(name,sex,age,addr,salary){this.name=name;this.sex=性别;这个。年龄=年龄;这个.addr=地址;this.salary=salary;}二、对象实例隐式传递this指针person.prototype.func_pro=function(){console.log(this);};letSakura=newperson("Sakura","Female",16"FateStayNight",10000000000);letIllyasviel=newperson("Illyasviel","Female",14,"FateStayNight",9999999999);Sakura.func_pro();Illyasviel.func_pro();console.日志(”------------------------------"+"\n\n");三、newandprototype1、总结:console.log("newandprototype");//1、letvariable={};//2、nodejs中的每个对象都有一个__proto__属性//建立两个对象之间的关联//一个对象可以使用__proto__来关联另一个对象//__proto__(对象内部原型的引用):prototype(Prototypeoftheobject)Shallow复制//__proto__和原型指向同一个对象引用//3.对象实例作为this指针的指针传递给下面的函数//4.调用这个函数2.你可以通过prototype.key=value来扩展对象ElffunctionElf(name){this.name=name;console.log("Elf\t"+name);}console.log("对象Elf可以通过prototype.key=value进行扩展");Elf.prototype.love=function(){console.log("%slove'DATEALIVE!'",this.name);};letYuzuru=newElf("Yuzuru");letKaguya=newElf("Kaguya");Yuzuru.love();Kaguya.love();console.log("------------------------------------------------------"+"\n\n");3.Instance.__proto__和method.prototype指向同一个对象引用console.log("Instance.__proto__和method.prototype指向同一个对象");console.log(Yuzuru.__proto__);console.log(Elf.prototype);console.log("-----------------------------------------------------"+"\n\n");letfunc_data=function(){console.log("func_data");};func_data.prototype.func_test=function(){console.log("func_test",this);};//instance.__proto__和method.prototype指向同一个对象引用console.log("instance.__proto__和method.prototype指向同一个对象引用");console.log(Yuzuru.__proto__);console.log(Elf.prototype);console.log("-----------------------------------------------------"+"\n\n");letfunc_data=function(){console.log("func_data");};func_data.prototype.func_test=function(){控制台。日志(“func_test”,这);};4。Instance.__proto__和method.prototype分别属于两个不同的字典表{}console.log("Instance.__proto__和method.prototype分别指向两个不同的字典表{}");letdata=newfunc_data();data.name="Innocence";data.__proto__.func_test();data.func_test();console.log("----------------------------------------------------"+"\n\n");5.对象实例可以看成是字典表//数据可以看成是表console.log("数据可以看成是表");//隐式调用thisdata.func_test();//显示调用这个Pass数据作为函数test_funcdata.__proto__.func_test.call(data);console.log("---------------------------------------------------"+"\n\n");6.调用值的顺序data.func_test=function(){console.log("newfunc_test",this);};data.func_test();//data.key_func会先到对象中查找是否有这样的实例表中的键,如果没有,则在其__proto__中搜索
