work
This commit is contained in:
parent
4c531b5ae7
commit
d4c714cbe1
261 changed files with 7370 additions and 546 deletions
|
@ -0,0 +1,32 @@
|
|||
function Clock(options) {
|
||||
this._template = options.template;
|
||||
}
|
||||
|
||||
Clock.prototype._render = function render() {
|
||||
var date = new Date();
|
||||
|
||||
var hours = date.getHours();
|
||||
if (hours < 10) hours = '0' + hours;
|
||||
|
||||
var min = date.getMinutes();
|
||||
if (min < 10) min = '0' + min;
|
||||
|
||||
var sec = date.getSeconds();
|
||||
if (sec < 10) sec = '0' + sec;
|
||||
|
||||
var output = this._template.replace('h', hours).replace('m', min).replace('s', sec);
|
||||
|
||||
console.log(output);
|
||||
};
|
||||
|
||||
Clock.prototype.stop = function() {
|
||||
clearInterval(this._timer);
|
||||
};
|
||||
|
||||
Clock.prototype.start = function() {
|
||||
this._render();
|
||||
var self = this;
|
||||
this._timer = setInterval(function() {
|
||||
self._render();
|
||||
}, 1000);
|
||||
};
|
|
@ -0,0 +1,13 @@
|
|||
function extend(Child, Parent) {
|
||||
Child.prototype = inherit(Parent.prototype);
|
||||
Child.prototype.constructor = Child;
|
||||
Child.parent = Parent.prototype;
|
||||
}
|
||||
|
||||
function inherit(proto) {
|
||||
function F() {}
|
||||
F.prototype = proto;
|
||||
return new F;
|
||||
}
|
||||
|
||||
// ваш код
|
|
@ -0,0 +1,35 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Часики в консоли</title>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- исходные часы, от них нужно унаследовать -->
|
||||
<script src="clock.js"></script>
|
||||
<script>
|
||||
var clock = new Clock({
|
||||
template: 'h:m:s'
|
||||
});
|
||||
clock.start();
|
||||
|
||||
|
||||
/* ... ваш код для ExtendedClock */
|
||||
|
||||
/*
|
||||
Надо: часы, которые тикают раз в 10 секунд (точность 10000)
|
||||
var lowResolutionClock = new ExtendedClock({
|
||||
template: 'h:m:s',
|
||||
precision: 10000
|
||||
});
|
||||
|
||||
lowResolutionClock.start();
|
||||
*/
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue