FORK
by aprudencio
HTML
<div class="console t1"></div>
<br />
<div class="console t2"></div>
CSS
.console {
background:black;
padding: 5px;
border: 1px solid green;
color:white;
width: 300px;
}
JavaScript
var ctest = function () {
return {
target:null,
funcion: function () {
$(this.target).html("Se ejecutó "+this.target);
},
marker: null,
intervalEv: null,
ev: function () {
var d = new Date();
if (d.getSeconds() == this.marker) this.funcion();
},
setMarker:function(){
var ahora = new Date();
this.marker = ahora.getSeconds() + 3;
},
empezar: function () {
var obj = this;
this.intervalEv = setInterval(function(){obj.ev();}, 1000);
}
};
};
var t1 = new ctest();
t1.setMarker();
t1.target = ".t1";
var t2 = ctest();
t2.marker = t1.marker;
t2.target = ".t2";
t1.empezar();
t2.empezar();