javascript - Memory efficiency in objects -


is either of these patterns more or less efficient other?

pattern 1:

var jso = new class({    initialize: function () {      // code    },    hilitefield: function () {      // code    } }); 

pattern 2:

var jso = new class({    initialize: function () {      this.hilitefield = hilitefield.bind(this);      // code      } }); var hilitefield = function () {   // code } 

having multiple methods external class , scope chain, opposed behind class 'namespaced' methods can't better, imo.

don't pattern #2 several reasons:

  • manageability - having bind reference each external function class going hard do.
  • readability - having indicate function being used class going task
  • extendibility - because functions outside of jso class prototype, classes extend jso or use mixin won't able access external methods.

that being said, memory standpoint - test say, pattern 1 have smaller overhead because it's defined once on prototype , not in every instance individually.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -