Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
function Increment(){
this.v = 0;
}
Increment.prototype.toString = function(){
return ++this.v;
}
var increment = new Increment();
alert(increment); /* 1 */
alert(increment); /* 2 */
alert(increment + increment); /* 7 */
function Increment() {
var i = 0;
this.toString = function() {
return ++i;
}
}
var increment = new Increment();
alert(increment);
alert(increment);
alert(increment + increment);
Specifically so, without methods in any way. And with methods, something like this:
// конструктор
function Increment() {
this.value = 1;
}
// метод в прототипе
Increment.prototype.val = function(speed) {
return this.value++;
};
//значение поля по умолчанию
Increment.prototype.value = 0;
//Собственно, код
var increment = new Increment();
alert(increment.val()); /* 1 */
alert(increment.val()); /* 2 */
alert(increment.val() + increment.val()); /* 7 */
increment = i++
what exactly is the catch? Or do you think that children's puzzles should be solved for you in the toaster?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question