Javascript Number add()

Description

Javascript Number add()

Number.prototype.add = function() {
  var newArgs = [].slice.call(arguments);
  newArgs.push(this.valueOf());/*from   w w  w. ja v  a2  s.c  o m*/
  return(add.apply(this, newArgs));
};

Javascript Number add()

//add new function to Number
Number.prototype.add = function () {
    return this + [].slice.apply(arguments).reduce(function (a, b) {
            "use strict";
            return a + b;
        },0);//  w  w  w  . j  av a 2s  .co  m
}



PreviousNext

Related