-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.js
More file actions
87 lines (72 loc) · 2.37 KB
/
object.js
File metadata and controls
87 lines (72 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const now = new Date();
console.log(now);
console.log(now.getFullYear());
console.log(now.getMonth() + 1);
console.log(now.getDate());
console.log(now.getTime());
console.log(now.__proto__);
console.log(now.__proto__.__proto__);
console.log(now.__proto__.__proto__.__proto__);
const numRegx = /[0-9]+/;
console.log(numRegx.test("我是1只漆黑小猫"));
console.log(numRegx.test("我是一只漆黑小猫"));
const text = "复旦中文真是要完蛋了啊";
console.log(text);
const safeText = text.replace(/复旦中文/, "****");
console.log(safeText);
//原型本质
const obj1 = {};
console.log(obj1.__proto__);
console.log(obj1.__proto__ === Object.prototype);
console.log(obj1.__proto__.__proto__);
//函数的双重身份
function foo() {};
//函数是对象
console.log(foo.__proto__);
const foo2 = new foo();
//函数自己拥有prototype
console.log(foo.prototype === foo2.__proto__);
//作为实例创建的foo2的原型是foo
console.log(foo.__proto__ == Function.prototype);
console.log(Function.prototype.__proto__ == Object.prototype);
console.log(Object.__proto__);
// function myNew(fn, ...args){
// const obj = Object.create(fn.prototype)
// const result = fn.apply(obj, args)
// return result instanceof Object ? result : obj
// }
//我按指定一个全局变量,这样可以改变下面car.model的结果
globalThis.model = "Teala"
function car(model){
console.log("正在执行car函数")
this.model = model;
this.year = 2024
return function(){
return this.model;
}
}
const c = new car("特斯拉")
console.log(c.model);//return的是一个函数,盲猜肯定undefined这个model属性
console.log(c());//这里的this应该是全局,找不到,应该是undefined
console.log(c instanceof car);//c实际上即成的已经不是prototype,而已return回来的函数吧?
//class的本质
class Person {
constructor(name) {
this.name = name
}
say(){
return "hello" + this.name;
}
}
const greeting = new Person("liqi");
console.log(greeting.name);
console.log(greeting.say());
//易错考点
console.log(Function.__proto__ === Function.prototype);
console.log(Object.__proto__ == Function.prototype);
console.log(typeof Object);
console.log(Function.prototype.__proto__ == Object.prototype);
console.log(Object.prototype.__proto__ === null);
let str = "liqi";
str.age = 3;
console.log(str.age);