We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
__proto__
function myNew() { // 1. 创建一个新对象 let obj = {}; // 2. 创建的对象通过__proto__链接到函数的原型(继承函数的属性及方法) let fn = [].shift.call(arguments); obj.__proto__ = fn.prototype; // 3. this指向当前新对象 let result = fn.apply(obj, arguments); // 4. 返回对象(若函数没有返回对象类型,那么自动返回new新创建的对象) return result instanceof Object ? result : obj; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
new操作符究竟做了些什么事情:
__proto__
链接到函数的原型模拟new操作符
The text was updated successfully, but these errors were encountered: