1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Number.prototype.add = function (x) {
return this + x;
};

Number.prototype.subtract = function (x) {
return this - x;
};

Number.prototype.iterate = function () {
var result = [];
for (var i = 0; i < this; i++) {
result.push(i);
}
return result;
};

Number.prototype = Object.defineProperty(Number.prototype, "double", {
get: function () {
return this + this;
},
});

Number.prototype = Object.defineProperty(Number.prototype, "square", {
get: function () {
return this * this;
},
});

console.log((8)["add"](2), (8).add(2), (8).add(2));
console.log((8).add(2).subtract(2));
console.log((8).iterate());
console.log((8).double.square);
Edited on