# 判断字符串的值是否相等
可以直接 s1==ss2
# 字符串的 match 和 matchAll 方法
var TestPrototype = function (num) { | |
this.propA = num; | |
this.methodA = function () { | |
console.log(this.propA); | |
return this.propA; | |
} | |
} | |
TestPrototype.prototype = { | |
methodB: function () { | |
console.log(this.propA); | |
return this.propA; | |
} | |
} | |
// 在原型对象中使用的 this,未理解 | |
var objA = new TestPrototype(1); | |
objA.methodA() // 1 | |
objA.methodB() // 1 | |
var objB = new TestPrototype(2); | |
objB.methodA() // 2 | |
objB.methodB() // 2 | |
console.log(objA === objB); //false | |
console.log(objA.methodA === objB.methodA); //false | |
console.log(objA.methodB === objB.methodB); //true | |
// 从上面可以看到,两个对象 objA 和 objB 的原型对象是同一个的,但是他们在使用 this | |
// 打印的时候,是能够正确寻找到 this 指向的继承的最后一个对象的(这里是用继承的么?) | |
let temp = new Array(); |
# this 的指向问题
彻底搞懂 JavaScript 中的 this 指向问题 - 西岭老湿的文章 - 知乎
https://zhuanlan.zhihu.com/p/42145138
https://juejin.cn/post/7073501330446221326#heading-5
let myFunc = function(...x) { | |
console.log(x); | |
console.log(arguments); | |
let arr = [...arguments]; | |
console.log(arr); | |
console.log(arr.slice(2)); | |
} | |
let myArgs = [1, 2, 3, 4, 5]; | |
myFunc(...myArgs); | |
// myFunc(1, 2, 3, 4, 5); |
# 数组
数组的长度可以自行自动增长的。