-
Notifications
You must be signed in to change notification settings - Fork 1
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
Note:JavaScript面对象系统之构造器 #7
Labels
documentation
Improvements or additions to documentation
Comments
JavaScript构造器概述作用
类与构造器在 ECMAScript 6 之后,函数可以简单地分为三个大类:
在 ECMAScript 6 方法特性
总结
【ECMAScript 6】 this创建顺序
f = new Function;
f instanceof Function // true
f() //undefined MyFunction = function() {};
MyFunction.prototype = new Function;
f = new MyFunction;
[f instanceof MyFunction, f instanceof Functcion]
// [ true, true ]
f() //TypeError: f is not a funct
ECMAScript 6 的类是由父类或祖先类创建this实例的。
class MyFunction extends Function { }
f = new MyFunction;
f() //undefined 用户返回 new 结果规则
## (注:ES3之前将抛出异常)
new (function() {return 1}); // {}
## 非派生类的构造方法返回无效值
new (class { constructor() { return 1 } }) //{}
## 派生类的构造方法返回无效值
new (class extends Object { constructor() { return 1 } }) // TypeError: Derived constructors may only return object or undefined 知识总结
推荐&打赏
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: