JS知识点

本文探讨了JavaScript中的一些实用技巧,包括类方法的枚举性差异、正则表达式的灵活运用、扩展字符集的理解及for循环中i++与++i的区别等。

找个地方随手记录看到的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吧,虽然影响几乎可以忽略


转载于:https://www.cnblogs.com/azerothmemoir/p/6723351.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值