Буду благодарен за помощь в понимании замыкания не стандартного
собственно хочу написать простой скрипт часов
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
jQuery.fn.digitalWatch = function() {
var el = $(this),
clock = this,
init = function(){
var date = new Date();
var hours = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
if (hours < 10) hours = "0" + hours;
if (minutes < 10) minutes = "0" + minutes;
if (seconds < 10) seconds = "0" + seconds;
el.html( hours + ":" + minutes + ":" + seconds );
};
init();
}
$('#clock').digitalWatch();
});
</script>
</head>
<body>
<div id="clock"></div>
</body>
</html>
пытаюсь его заставить работать, но пока что тщетно
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
jQuery.fn.digitalWatch = function() {
var el = $(this),
clock = this,
init = function(){
var date = new Date();
var hours = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
if (hours < 10) hours = "0" + hours;
if (minutes < 10) minutes = "0" + minutes;
if (seconds < 10) seconds = "0" + seconds;
el.html( hours + ":" + minutes + ":" + seconds );
};
setTimeout(function(){
(function(newClock){newClock.init()})(clock);
}, 1000);
}
$('#clock').digitalWatch();
});
</script>
</head>
<body>
<div id="clock"></div>
</body>
</html>