JavaScript/constructor:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
创建页面,内容为“== 引言 == constructor 是一种用于创建和初始化class创建的对象的特殊方法。<ref>constructor-JavaScript|MDN[EB/OL].https://developer.mozilla.org/…”
 
Kangkk​(留言 | 贡献)
第7行: 第7行:


{{Leftrightflex|<syntaxhighlight lang="javascript">
{{Leftrightflex|<syntaxhighlight lang="javascript">
'ff'.constructor
'ff'.constructor;
[1,2].constructor
[1,2].constructor;
{'a':'1'}.constructor
{'a':'1'}.constructor;
new Object.constructor
new Object.constructor;
var a = new Object;
a.constructor;
</syntaxhighlight>|{{consoleout|<pre>
</syntaxhighlight>|{{consoleout|<pre>
ƒ String() { [native code] }
ƒ String() { [native code] }
第16行: 第18行:
VM317:1 Uncaught SyntaxError: Unexpected token ':'
VM317:1 Uncaught SyntaxError: Unexpected token ':'
ƒ anonymous() {}
ƒ anonymous() {}
ƒ Object() { [native code] }
</pre>}}}}
</pre>}}}}

2020年6月23日 (二) 10:29的版本

引言

constructor 是一种用于创建和初始化class创建的对象的特殊方法。[1]

constructor([arguments]) { ... }

判断

constructor 属性返回对创建此对象的数组函数的引用。

模板:Leftrightflex