0

I know it is a wired question but I want to make this syntax to work in javascript:

var a = (5).plus(3).minus(6); //2

Inspired from: http://dmitry.baranovskiy.com/post/31797647

I have checked the Answer on SO but not getting any idea for dot(.) in the syntax.

NullPointer
  • 7,094
  • 5
  • 27
  • 41

1 Answers1

5

@jonrsharpe's proposal works:

Number.prototype.plus = function(b) {
  return this + b;
}

Number.prototype.minus = function(b) {
  return this - b;
}

var a = (5).plus(3).minus(6); // 2

console.log(a);
Josu Goñi
  • 1,178
  • 1
  • 10
  • 26