getify/cloud-sweeper

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

Open

#25 geöffnet am 16. Feb. 2016

Auf GitHub ansehen
 (7 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)JavaScript (17 Forks)github user discovery
help wanted

Repository-Metriken

Stars
 (96 Stars)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

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();

Contributor Guide