JS Array 对象中的constructor的定义和用法
constructor 属性返回对创建此对象的数组函数的引用。
返回值是函数的引用,不是函数名:
JavaScript 数组 constructor 属性返回 function Array() { [native code] }
JavaScript 数字 constructor 属性返回 function Number() { [native code] }
JavaScript 字符串 constructor 属性返回 function String() { [native code] }
如果一个变量是数组你可以使用 constructor 属性来定义。
JS Array 对象中的constructor浏览器的兼容性
Chrome | Inter Explorer | Firefox | Safari | Opera |
---|---|---|---|---|
YES | YES | YES | YES | YES |
JS Array 对象中的constructor的语法和例子
Array constructor语法:
array.constructor
js constructor判断是不是数组array
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>js constructor判断是不是数组 - Break易站(breakyizhan.com)</title> </head> <body> <p id="demo">点击按钮创建一个数组,并显示判断。</p> <button onclick="myFunction()">点我</button> <script> function myFunction() { var fruits = ["Banana", "Orange", "Apple", "Mango"]; if (fruits.constructor==Array) { document.write("This is an Array"); } if (fruits.constructor==Boolean) { document.write("This is a Boolean"); } if (fruits.constructor==Date) { document.write("This is a Date"); } if (fruits.constructor==String) { document.write("This is a String"); } } </script> </body> </html>
js constructor显示数组array的构造函数
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>js constructor显示数组的构造函数- Break易站(breakyizhan.com)</title> </head> <body> <p id="demo">点击按钮创建一个数组,并显示它的构造函数。</p> <button onclick="myFunction()">点我</button> <script> function myFunction() { var bill=new employee("Bill Gates","Engineer",1985); var x=document.getElementById("demo"); x.innerHTML=bill.constructor; } function employee(name,job,born) { this.name=name; this.job=job; this.born=born; } </script> </body> </html>
JS相关文章
分享笔记
笔记需要是本篇文章内容相关的扩展!