-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
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
第 5 题:new操作符都做了什么 #5
Comments
lat 是什么声明? |
写错了,let |
上述说的还是 ES5 时的实现方式 |
if (typeof(res) == "object" && res || typeof(res) == "function") {
return res;
} 这里别忘了 typeof null == 'object' 的情况 |
|
function myNew(func, ...ages) { function Person (name, age) { 调用:myNew(Person, 'qq', 12) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
四大步骤:
1、创建一个空对象,并且 this 变量引用该对象,// lat target = {};
2、继承了函数的原型。// target.proto = func.prototype;
3、属性和方法被加入到 this 引用的对象中。并执行了该函数func// func.call(target);
4、新创建的对象由 this 所引用,并且最后隐式的返回 this 。// 如果func.call(target)返回的res是个对象或者function 就返回它
The text was updated successfully, but these errors were encountered: