('()', 5000); In addition, I also thought of saving the object as an array before and then referencing the call. The code is as follows:
function ObjectClass (property) {
= property;
= ;
[++] = this;
= ObjectClass_method;
}
= 0;
= new Array();
function ObjectClass_method () {
setTimeout('[' + + '].method();', 5000);
}
var obj1 = new ObjectClass('feelinglucky');
(); However, I feel that the first method mentioned above is much clearer.
Postscript, Javascript does seem to be in many places that need to be treated with caution, especially the object mechanism. Just as I said before, Javascript is not more complicated than other languages, but it is not as simple as you imagined.
PS: After completing this question, Google found that other brothers had already solved such problems, such as here and here, so you can compare and refer to it.
--------------------------------------------------------------------------------
Update, thanks to the reminder of Sheneyan brothers, there is another way to implement it through Closure (closure). The code is as follows:
var Obj = function(msg){
= msg;
= function() {
alert();
();
}
var _self = this;
= function() {
setTimeout(function(){_self.shout()}, 5000);
}
}
var testObj = new Obj("Hello,World!");
();It seems that this question can no longer harm people :^)
Previous page12Read the full text