Создание счеткика
Здравствуйте, нужно создать счетчик. Только числа должны увеличатся от 0 до максимального числа, которое указаное
|
Счетчик чего?
|
Counter={
create: function(max){
var o=Object.create(this)
o.max=max
return o
},
value: 0,
step: function(){
with(this) with(console){
if(value>=max) return log("done")
log(++value)
}
}
}
with(Counter.create(3)) step(), step(), step(), step()
with(Counter.create(5)) step(), step(), step(), step(), step(), step()
|
либо так
createCounter=function(max){
var value=0
return function(){
with(console){
if(value>=max) return log("done")
log(++value)
}
}
}
counter=createCounter(3)
counter()
counter()
counter()
counter()
counter=createCounter(5)
counter()
counter()
counter()
counter()
counter()
counter()
|
var myCounter = {
max: 0,
position: 0,
get cur() {
if (this.position == this.max) this.position = 0;
this.position += 1;
return this.position;
},
set cur(arg) {
this.max = arg;
}
};
myCounter.cur = 3;
console.log(myCounter.cur);
console.log(myCounter.cur);
console.log(myCounter.cur);
console.log(myCounter.cur);
function next(max) {
var i = 0;
return function () {
i = i < max ? i + 1 : 1;
return i;
};
}
var current = next(3);
console.log(current());
console.log(current());
console.log(current());
console.log(current());
|
Вложений: 1
Как на сайте
http://www.codefire.com.ua/ |
|
А как с ним работать. Например с первым. Код разметки добавил в html, в файл js скинул код с lines, но анимации нету
|
| Часовой пояс GMT +3, время: 09:37. |