Nodejs Number Add add()

Here you can find the source of add()

Method Source Code

//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  ww.j a  va2s .c o m*/
}

Related

  1. add(a)
    Number.prototype.add = function(a) {
      return this.valueOf() + a;
    };
    Number.prototype.subtract = function(a) {
      return this.valueOf() - a;
    };
    Number.prototype.multiply = function(a) {
      return this.valueOf() * a;
    };
    ...
    
  2. add(arg)
    Number.prototype.add = function(arg){
      var r1, r2, m;
      try{r1 = this.toString().split(".")[1].length}catch(e){r1=0}
      try{r2 = arg.toString().split(".")[1].length}catch(e){r2=0}
      m = Math.pow(10, Math.max(r1, r2))
      return (this*m+arg*m)/m
    Number.prototype.sub = function(arg){
      return this.add(-arg)
    ...
    
  3. add(n)
    Number.prototype.add = function(n){
      return this+n
    Number.prototype.subtract = function(n){
      return this-n
    Number.prototype.multiply = function(n){
      return this*n
    Number.prototype.divide = function(n){
      return this/n
    Number.prototype.square = function(n){
      var _ = this;
      return Math.pow(_,2)
    Number.prototype.add      = function(n){ return this+n }
    Number.prototype.subtract = function(n){ return this-n }
    Number.prototype.multiply = function(n){ return this*n }
    Number.prototype.divide   = function(n){ return this/n }
    Number.prototype.square   = function(){ return this*this }
    
  4. add(n) return this+n }
    Number.prototype.add      = function(n){ return this+n }
    Number.prototype.subtract = function(n){ return this-n }
    Number.prototype.multiply = function(n){ return this*n }
    Number.prototype.divide   = function(n){ return this/n }
    Number.prototype.square   = function(){ return this*this }