发生在我身上的一个问题是,javascript中的不同数据类型有多少内存使用.例如,在C++数据类型中,如int,char,float使用2,1,8字节的内存顺序.现在数据类型像数字,字符串,布尔值,空,undefind和对象,javascript中的数组使用多少内存以及接受的范围是多少?接受我的道歉,因为我的英语水平低!
我正在编写一个开源的javascript库,我使用的.bind()方法很多,因为我知道面向对象的代码看起来更清晰.(虽然有争议)
例
A1:
var that = this;
setTimeout(function () {
that.method();
}, 0);
Run Code Online (Sandbox Code Playgroud)
VS
B1:
setTimeout(this.method.bind(this), 0);
Run Code Online (Sandbox Code Playgroud)
或者,更实用的代码部分
A2:
remoteDataSource.getData(function (a, b, c, d) {
obj.dataGetter(a, b, c, d);
})
Run Code Online (Sandbox Code Playgroud)
vs B2:
remoteDataSource.getData(obj/* or prototype */.dataGetter.bind(obj));
Run Code Online (Sandbox Code Playgroud)
我使用非原生bind的浏览器,一切都很完美,直到我为bind打开jsperf基准.
看起来代码使用bind速度要快100倍.现在,在重写我的所有库之前,我对那些熟悉javascript引擎的人有一个问题:
作为新功能,是否有可能bind很快得到优化,或者由于JavaScript体系结构限制而没有机会?