javascript 關於 propertyIsEnumerable 的問題?

時間 2021-05-31 02:24:09

1樓:

你應該用 `arr.propertyIsEnumerable('length')`。`arr.

propertyIsEnumerable(length) === arr.propertyIsEnumerable(window.length) === arr.

propertyIsEnumerable(0)`,假設你所在的視窗沒有 frame 的話,因為 `window.length` 就是 frame 的數目。

2樓:墨磊

這例子中 length 並不是 Array.length

length 是 window.length。(謝 @Cat Chen 指正)

還是 {} 可用性如下:

var a = [111, 222, 333];

console.log(a[0], a.propertyIsEnumerable(0));

console.log(a[1], a.propertyIsEnumerable(1));

var b = ;

console.log(b['constructor'], b.propertyIsEnumerable('constructor'));

console.log(b[0], a.propertyIsEnumerable(0));

建構函式:

function firstConstructor()

firstConstructor.prototype.firstMethod = function() {};

var firstObj = new firstConstructor();

console.log(firstObj.propertyIsEnumerable('a'),firstObj.propertyIsEnumerable('b'));

console.log(firstObj.propertyIsEnumerable('firstMethod'));

有 a,b, prototype 不管。

所以,Array.propertyIsEnumerable('length'); // return false

關於javascript中defineProperty的問題?

牧歌 為了避免衝突,讓上下文更安全。 itlr Object.defineProperty 更強大 This method allows precise addition to or modification of a property on an object.Normal property ad...

javascript框架中關於function函式表示式使用的問題

Saviio 我一點都不覺得這有什麼不好理解或者困惑的。設命名空間如下 varnamespace 乙個是例項屬性 namespace foo function arg1 arg2 var ins newnamespace foo 10 20 乙個是靜態方法 namespace foo isEven ...

javascript面試題,關於連續賦值的坑?

破軍 假設 的位址為 0xfff a 指向該位址,b 又指向a,所以在定義階段,a和b 的位址都指向了 0xfff 接著就是重頭戲了且在連等中,相當於是乙個函式體 只有當結束的時候才能改變位址,因為此原因,導致a.c中的a並沒有因為等號後面的a的指向改變而改變,a.c中的a依然指向 0xfff,而等...