javascript - chrome 疑似克隆對象的優化?
怪我咯
怪我咯 2017-04-10 14:59:24
0
0
356


http://jsperf.com/immutable-vs-mutable

Safari 和 Firefox 均符合預期,二者性能相差無幾

var VectorMutable = function(x, y) { this.x = x; this.y = y; };
var Vector = function(x, y) { this.x = x; this.y = y; };

VectorMutable.prototype.clone = function() { return new VectorMutable(this.x, this.y); };
VectorMutable.prototype.add = function(x, y) { this.x += x; this.y += y; return this; };
Vector.prototype.add = function(x, y) { return new Vector(this.x+x, this.y+y); };

var result1 = new VectorMutable(0,0).clone().add(1,2);
var result2 = new Vector(0,0).add(1,2);

猜測是 chrome 對克隆對象的額外優化所致

怪我咯
怪我咯

走同样的路,发现不同的人生

membalas semua(0)
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!