Created
January 6, 2014 16:11
-
-
Save soharu/8285069 to your computer and use it in GitHub Desktop.
Example of constructor property 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Range(from, to) { | |
this.from = from; | |
this.to = to; | |
} | |
Range.prototype = { | |
constructor: Range, | |
includes: function (x) { | |
return this.from <= x && x <= this.to; | |
}, | |
foreach: function (f) { | |
for (var x = Math.ceil(this.from); x <= this.to; x++) | |
f(x); | |
}, | |
toString: function () { | |
return "(" + this.from + "..." + this.to + ")"; | |
} | |
} | |
var r = new Range(1, 3); | |
r.includes(2); | |
r.foreach(console.log); | |
console.log(r); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment