We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent afd9f18 commit 3b60ec6Copy full SHA for 3b60ec6
doc/zhtw/object/hasownproperty.md
@@ -1,4 +1,4 @@
1
-## `hasOwnProperty`
+## `hasOwnProperty`
2
3
為了判斷一個物件是否包含 *自定義* 屬性而 *不是* [原形](#object.prototype)上的屬性,我們需要使用繼承 `Object.prototype` 的 `hasOwnProperty` 方法。
4
@@ -8,9 +8,9 @@
8
`hasOwnProperty` 是 JavaScript 中唯一一個處理屬性但是 **不** 找原型鏈的函式。
9
10
// 修改 Object.prototype
11
- Object.prototype.bar = 1;
+ Object.prototype.bar = 1;
12
var foo = {goo: undefined};
13
-
+
14
foo.bar; // 1
15
'bar' in foo; // true
16
@@ -35,6 +35,8 @@ JavaScript **不會** 保護 `hasOwnProperty`被占用,因此如果碰到存
35
// 使用其他對象的 hasOwnProperty,並將其上下設置為 foo
36
({}).hasOwnProperty.call(foo, 'bar'); // true
37
38
+ // 也可以透過原生 Object prototype 的 hasOwnProperty 函數來達成目的
39
+ Object.prototype.hasOwnProperty.call(foo, 'bar'); // true
40
41
### 結論
42
0 commit comments