Skip to main content

Home/ javascript/ Group items tagged stackoverflow

Rss Feed Group items tagged

Javier Neira

Is JavaScript object-oriented? - Stack Overflow - 1 views

  • Well this is broken. Since the function assigned to getValue is no longer in scope with _value it can't access it. We would need to promote _value to an attribute of this but that would make it accessable outside of the control of code written for the class, hence encapsulation is broken.
Javier Neira

Three map implementations in javascript. Which one is better? - Stack Overflow - 1 views

  • if (!Array.prototype.map) {  Array.prototype.map = function(fun /*, thisp*/)   {    var len = this.length >>> 0;  // make sure length is a positive number    if (typeof fun != "function") // make sure the first argument is a function      throw new TypeError();    var res = new Array(len);  // initialize the resulting array    var thisp = arguments[1];  // an optional 'context' argument    for (var i = 0; i < len; i++) {      if (i in this)        res[i] = fun.call(thisp, this[i], i, this);  // fill the resulting array    }    return res;  };}
  •  
    if (!Array.prototype.map) { Array.prototype.map = function(fun /*, thisp*/) { var len = this.length >>> 0; // make sure length is a positive number if (typeof fun != "function") // make sure the first argument is a function throw new TypeError(); var res = new Array(len); // initialize the resulting array var thisp = arguments[1]; // an optional 'context' argument for (var i = 0; i < len; i++) { if (i in this) res[i] = fun.call(thisp, this[i], i, this); // fill the resulting array } return res; }; }
1 - 10 of 10
Showing 20 items per page