*#type.js
复制代码代码如下:
orang fungsi (nama, usia) {
this.name = name;
this.age = usia;
}
var d = {an: 'objek'};
var a = ['apel', 'pisang'];
var f = function () {};
var s = 'David';
var n = 33;
var b = true;
var o = objek baru ();
var orang = orang baru ('Mark', 22);
console.log (typeof (d) + ':' + d.constructor);
console.log (typeof (a) + ':' + a.constructor);
console.log (typeof (f) + ':' + f.constructor);
console.log (typeof (s) + ':' + s.constructor);
console.log (typeof (n) + ':' + n.constructor);
console.log (typeof (b) + ':' + b.constructor);
console.log (typeof (o) + ':' + o.constructor);
console.log (typeof (orang) + ':' + orang.constructor);
运行 $ node type.js 得
复制代码代码如下:
Object: Function Object () {[kode asli]}
Objek: Function Array () {[Kode Asli]}
Fungsi: fungsi fungsi () {[kode asli]}
String: function string () {[kode asli]}
Nomor: Nomor fungsi () {[kode asli]}
boolean: function boolean () {[kode asli]}
Object: Function Object () {[kode asli]}
Objek: function person () {[kode asli]}
可见, 使用 tipe 操作符和 konstuskonsor 属性检测对象类型返回值是存在差异的.
如果变量是数组, tipe objek, konstruktor 属性返回 array;
如果变量是构造函数对象, tipe Objek 操作符返回, konstruktor 属性返回该构造函数
每个变量都有其 Konstruksi 属性, 这个属性不单单提供了这个是否对象, 还提供了这个对象是什么类型的对象. 总之, konstruktor 属性保存了一个指向对象的构造函数, 无论它是自定义的还是原生类型的对象.
有一点需要注意的是, 不同的浏览器对 tipe 操作符检测正则表达式会有所不同, yaitu 和 objek firefox 会返回 '.
好了 , 今天内容就先到这里了 , 小伙伴们如有疑问 , ,