cylon/dist/utils.js

57 lines
1.2 KiB
JavaScript
Raw Normal View History

2013-10-25 05:25:42 +08:00
/*
* utils
* cylonjs.com
*
* Copyright (c) 2013 The Hybrid Group
* Licensed under the Apache 2.0 license.
*/
(function() {
var __slice = [].slice;
2013-10-25 05:25:42 +08:00
global.every = function(interval, action) {
return setInterval(action, interval);
};
global.after = function(delay, action) {
return setTimeout(action, delay);
};
global.proxyFunctionsToObject = function(methods, target, base, force) {
2013-10-29 08:48:29 +08:00
var method, _fn, _i, _len;
if (base == null) {
base = this;
}
if (force == null) {
force = false;
}
2013-10-29 08:48:29 +08:00
_fn = function(method) {
return base[method] = function() {
2013-10-29 08:48:29 +08:00
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return target[method].apply(target, args);
};
};
for (_i = 0, _len = methods.length; _i < _len; _i++) {
method = methods[_i];
if (!force) {
if (typeof base[method] === 'function') {
continue;
}
}
2013-10-29 08:48:29 +08:00
_fn(method);
}
return base;
};
2013-10-25 05:25:42 +08:00
Number.prototype.seconds = function() {
return this * 1000;
};
Number.prototype.second = function() {
return this.seconds(this);
};
}).call(this);