getify/cloud-sweeper

refactor: use the constructor pattern on frequently made objects (perf)

開放

#25 建立於 2016年2月16日

 (7 則留言) (0 個反應) (0 位負責人)JavaScript (17 個分叉)github user discovery
help wanted

倉庫指標

星標
 (96 顆星)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

I'm not a big fan of the constructor pattern, as most people who follow me know.

But it does seem to help when objects have a predictable shape and are created frequently. NOTE: this has nothing to do with using classes as a design pattern. It's a way to declare the shape of the object in a way that the engine can pre-optimize for.

ex:

// instead of:
var obj = { x: .., y: .., z: .. }

// do:
function makeObj() {
   this.x = ..
   this.y = ..
   this.z = ..
}
var obj = new makeObj();

貢獻者指南