查看“︁JavaScript/constructor”︁的源代码
来自康健生活
←
JavaScript/constructor
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
== 引言 == constructor 是一种用于创建和初始化class创建的对象的特殊方法。<ref>constructor-JavaScript|MDN[EB/OL].https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Classes/constructor</ref> <blockquote><pre> constructor([arguments]) { ... }</pre></blockquote> ES2015 为没有指定构造函数的类提供了默认构造函数。 == 验证 == constructor 属性返回对创建此对象的数组函数的引用。 {{Double-columns|<syntaxhighlight lang="javascript"> 'ff'.constructor; [1,2].constructor; {'a':'1'}.constructor; new Object.constructor; var foo = new Object; foo.constructor; null.constructor; undefined.constructor; </syntaxhighlight>|{{consoleout|<pre> ƒ String() { [native code] } ƒ Array() { [native code] } VM317:1 Uncaught SyntaxError: Unexpected token ':' ƒ anonymous() {} ƒ Object() { [native code] } VM4070:1 Uncaught TypeError: Cannot read property 'constructor' of null at <anonymous>:1:6 VM4240:1 Uncaught TypeError: Cannot read property 'constructor' of undefined at <anonymous>:1:11 </pre>}}}} == 判断 == {{Double-columns|<syntaxhighlight lang="javascript"> new String().constructor===String; new Number().constructor===Number; new Array().constructor===Array; new Boolean().constructor===Boolean; new Object().constructor===Object; new Function().constructor===Function; new RegExp().constructor===RegExp; new Date().constructor===Date; new Error().constructor===Error; var foo = 1; foo.constructor===Number; BigInt('1').constructor === BigInt; "str".constructor===String; true.constructor===Boolean; Symbol().constructor===Symbol; new Map().constructor===Map; new Set().constructor===Set; var puz = new Promise((resolve,reject)=>{}); puz constructor===Promise; var xyz = new Proxy({},{}); xyz.constructor===Proxy </syntaxhighlight>|{{consoleout|<pre> true true true true true true true true true true true true true true true true true false </pre>}}}} == 继承 == == 兼容版本 == {| class="wikitable sortable" |- ! colspan=6| pc !! colspan=6| mobile !! server |- ! {{Vertical header|stp=1|chrome}} ! {{Vertical header|stp=1|Edge}} ! {{Vertical header|stp=1|Firefox}} ! {{Vertical header|stp=1|Internet Explorer}} ! {{Vertical header|stp=1|Opera}} ! {{Vertical header|stp=1|Safari}} ! {{Vertical header|stp=1|Android webview}} ! {{Vertical header|stp=1|Chrome for Android}} ! {{Vertical header|stp=1|Firefox for Android}} ! {{Vertical header|stp=1|Opera for Android}} ! {{Vertical header|stp=1|Safari on iOS}} ! {{Vertical header|stp=1|Samsung Internet}} ! {{Vertical header|stp=1|Node.js}} |- | 49 || 13 || 45 || NO || 36 || 9 || 49 || 49 || 45 || 36 || 9 || 5.0 || 6.0.0 |}
此页面嵌入的页面:
模板:Consoleout
(
查看源代码
)
模板:Double-columns
(
查看源代码
)
模板:Double-columns/style.css
(
查看源代码
)
模板:Transform
(
查看源代码
)
模板:Transform-rotate
(
查看源代码
)
模板:Vertical header
(
查看源代码
)
模板:Writing-mode
(
查看源代码
)
模块:Vertical header
(
查看源代码
)
返回
JavaScript/constructor
。
导航菜单
康健生活
搜索
user-page
通知
user-interface-preferences
个人工具
登录
五一
多读书,多运动,多到远处走走,再看看不一样的世界。