JS知识点

找个地方随手记录看到的JS知识点


var l = console.log.bind(console);
l('hello world');

类的内部方法是不可枚举的,但是使用Object.assign()方法添加的是可以枚举出来的

class P {
	constructor () {}
	toString () {}
	toValue () {}
}
Object.keys(P.prototype)
// []
class F {}
Object.assign(F.prototype, {
    toString(){},
    toValue(){}
})
Object.keys(F.prototype)
// ["toString", "toValue"]

正则表达式含有变量的处理

var str = '123'
var reg = new RegExp(str, 'g')
console.log('123哈哈哈哈'.replace(reg, ''))

扩展字符集由两个码元组成一个代码点

let str = String.fromCodePoint(134071) // "𠮷" 不是 "吉"
console.log(str.length) // 2
str.codePointAt()     //  134071
str.charCodeAt(0)   // 55362
str.charCodeAt(1)   //  57271
String.fromCharCode(str.charCodeAt(0))
String.fromCharCode(str.charCodeAt(1))

for循环里的i++与++i, 循环的结果是没有区别的
i++:Fetch i,copy i,increment i,return copy;
++i:Fetch i,increment i,return i;
i++要多拷贝一次副本,所以在算法里遇到for循环还是用++i吧,虽然影响几乎可以忽略


posted @ 2017-04-17 15:59  艾泽拉斯回忆录  阅读(132)  评论(0编辑  收藏  举报