new的作用
新⽣成了⼀个对象
链接到构造函数的原型
绑定 this
返回新对象
function new() {
let obj = new Object();
let Con = [].shift.call(arguments);
obj.__proto__ = Con.prototype
let result = Con.apply(obj,arguments);
return typeof result === 'object' ? result : obj;
}
instanceof的作用
instanceof可以正确的判断对象的类型
function instanceof(left, right) {
let prototype = right.prototype
left = left.__proto__
while(true) {
if(left === null)
return false
if(prototype === left)
return true
left = left.__proto__
}
}
博客介绍了new和instanceof的作用,指出instanceof可正确判断对象类型,这些内容属于前端开发中JavaScript的基础知识。
1076

被折叠的 条评论
为什么被折叠?



