
Function.call() Method
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Alphabetical Language Reference
|
531
// Store extra arguments. We'll pass them to meth later.
this.args = arguments.slice(3);
// Set an empty intervalID. Used with setInterval().
this.intervalID = -1;
// Start the countdown
this.start();
}
/*
* Method: start()
*/
CountDown.prototype.start = function () {
// Invoke the method-caller after this.delay milliseconds.
this.intervalID = setInterval(this, "invokeCallback", this.delay);
};
/*
* Method: stop()
*/
CountDown.prototype.stop = function () {
// Stop the interval so that it doesn't call the method again.
clearInterval(this.intervalID);
this.intervalID = -1;
};
/*
* Method: invokeCallback()
*/
CountDown.prototype.invokeCallback = function () {
// Time's up! Stop the countdown.
this.stop();
// Invoke the callback as a method of this.obj, and pass
// along this.args to use as method arguments.
this.callback.apply(this.obj, this.args);
};
// SAMPLE USE
// Create the countdown. Will invoke
// _root.output("hello", "world") after 1000 milliseconds.
count = new CountDown(_root, "output", 1000, "hello", "world");
// The method to invoke
function output (arg1, arg2) {
trace("output: " + arg1 + ", " + arg2);
}
See Also
Function.call(), the Arguments object; Chapter 12
Function.call() Method
invoke a function as an object method ...