Классы

function Range(from, to) { this.from = from; this.to = to; }

Range.prototype = { 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); console.log(r.includes(2)); // = true r.foreach(console.log); // = 1, = 2, = 3 console.log('' + r); // = '(1...3)'

Оценка статьи 0

Комментарии

Пока комментариев нет.