当前位置: 首页 > Web前端 > JavaScript

【JavaScript】new运算符的使用

时间:2023-03-26 20:57:01 JavaScript

newfunctionStudent(name){this.name=name}varstu=newStudent('tao')newfunctionStudent(name){//js会创建的原理atemporaryobject保存stu的属性//vartemp={}//Changethistopoint//this=temp//改变原型//this.__proto__=Student.prototypethis.name=name//然后返回thisstu//返回这个}