Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @see http://stackoverflow.com/a/7356528
- *
- * @param functionToCheck
- */
- function isFunction(functionToCheck) {
- var getType = {};
- return functionToCheck && getType.toString.call(functionToCheck) == '[object Function]';
- }
- /**
- * @param arg
- */
- function callback(arg) {
- if (isFunction(arg)) {
- return arg;
- }
- return function () {
- var obj = arg[0], method = arg[1];
- obj[method]();
- };
- }
- /**
- * Interval class
- */
- var Interval = $class({
- constructor: function (listener, time) {
- this.callback = callback(listener);
- this.time = time;
- this.timeout = false;
- },
- start: function () {
- var me = this;
- this.timeout = setTimeout(function () {
- me.callback();
- me.start(); // next iteration
- }, this.time);
- },
- pause: function () {
- clearTimeout(this.timeout);
- this.timeout = false;
- }
- });
- var f = new Foo();
- var i = new Interval([f, 'm'], 1000);
- i.start();
Advertisement
Add Comment
Please, Sign In to add comment