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 5017c64 commit 58aab91Copy full SHA for 58aab91
面试常见的手写题/17-Object.freeze.js
@@ -0,0 +1,35 @@
1
+const syn = Symbol(1)
2
+const obj = {
3
+ name: 'coderwei',
4
+ age: 13,
5
+ friend: {
6
+ name: 'test1',
7
+ },
8
+ [syn]: 123,
9
+}
10
+
11
+Object.prototype.dadad = '123'
12
13
+Object._freeze = function (obj) {
14
+ const ObjKey = Object.getOwnPropertyNames(obj)
15
+ const SymbolKey = Object.getOwnPropertySymbols(obj)
16
+ const keys = [...ObjKey, ...SymbolKey]
17
18
+ for (const key of keys) {
19
+ Object.defineProperty(obj, key, {
20
+ writable: false,
21
+ configurable: false,
22
+ })
23
+ }
24
25
26
+Object._freeze(obj)
27
28
+function hasOwnProtoType(obj, key) {
29
+ return Object.prototype.hasOwnProperty.call(obj, key)
30
31
+obj[syn] = '被修改了'
32
+obj.name = '被修改了'
33
+obj.age = '被修改了'
34
+obj.friend.name = '被修改了'
35
+console.log(obj)
0 commit comments