callback return

by toubia95

JavaScript

function First(x) {
  this.x = x;
  this.y = x * 2;
}

First.prototype.last = function(z, cb) {
  var result = this.y + z;
  if (cb) {
    result = cb(result, this);
  }
  return result;
};

function callback1() {
  return "callback1";
}

function callback2() {
  console.log("callback2");
}

console.log("new First(3).y //" + new First(3).y); //6
console.log("new First(3).last(2) // " + new First(3).last(2)); //8
console.log("return +TEST //" + new First(3).last(2, (function(n, d) {
  var toto = "-TOTO-";
  var tata = d.x;
  return n * 3 + toto + tata;
})));