more koltin lib clean up.
This commit is contained in:
@@ -6,6 +6,99 @@ function $A(iterable) {
|
||||
return results;
|
||||
}
|
||||
|
||||
(function () {
|
||||
|
||||
|
||||
function extend(destination, source) {
|
||||
for (var property in source)
|
||||
destination[property] = source[property];
|
||||
return destination;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function keys(object) {
|
||||
if (Type(object) !== OBJECT_TYPE) {
|
||||
throw new TypeError();
|
||||
}
|
||||
var results = [];
|
||||
for (var property in object) {
|
||||
if (object.hasOwnProperty(property)) {
|
||||
results.push(property);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
function values(object) {
|
||||
var results = [];
|
||||
for (var property in object)
|
||||
results.push(object[property]);
|
||||
return results;
|
||||
}
|
||||
|
||||
extend(Object, {
|
||||
extend:extend,
|
||||
keys:Object.keys || keys,
|
||||
values:values,
|
||||
});
|
||||
})();
|
||||
|
||||
|
||||
Object.extend(Function.prototype, (function () {
|
||||
var slice = Array.prototype.slice;
|
||||
|
||||
function update(array, args) {
|
||||
var arrayLength = array.length, length = args.length;
|
||||
while (length--) array[arrayLength + length] = args[length];
|
||||
return array;
|
||||
}
|
||||
|
||||
function merge(array, args) {
|
||||
array = slice.call(array, 0);
|
||||
return update(array, args);
|
||||
}
|
||||
|
||||
function argumentNames() {
|
||||
var names = this.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/)[1]
|
||||
.replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g, '')
|
||||
.replace(/\s+/g, '').split(',');
|
||||
return names.length == 1 && !names[0] ? [] : names;
|
||||
}
|
||||
|
||||
function bind(context) {
|
||||
if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this;
|
||||
var __method = this, args = slice.call(arguments, 1);
|
||||
return function () {
|
||||
var a = merge(args, arguments);
|
||||
return __method.apply(context, a);
|
||||
}
|
||||
}
|
||||
|
||||
function bindAsEventListener(context) {
|
||||
var __method = this, args = slice.call(arguments, 1);
|
||||
return function (event) {
|
||||
var a = update([event || window.event], args);
|
||||
return __method.apply(context, a);
|
||||
}
|
||||
}
|
||||
|
||||
function wrap(wrapper) {
|
||||
var __method = this;
|
||||
return function () {
|
||||
var a = update([__method.bind(this)], arguments);
|
||||
return wrapper.apply(this, a);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
argumentNames:argumentNames,
|
||||
bind:bind,
|
||||
bindAsEventListener:bindAsEventListener,
|
||||
wrap:wrap
|
||||
}
|
||||
})());
|
||||
|
||||
var isType = function (object, klass) {
|
||||
current = object.get_class();
|
||||
while (current !== klass) {
|
||||
@@ -142,134 +235,6 @@ var Namespace = (function () {
|
||||
};
|
||||
})();
|
||||
|
||||
(function () {
|
||||
|
||||
|
||||
function extend(destination, source) {
|
||||
for (var property in source)
|
||||
destination[property] = source[property];
|
||||
return destination;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function keys(object) {
|
||||
if (Type(object) !== OBJECT_TYPE) {
|
||||
throw new TypeError();
|
||||
}
|
||||
var results = [];
|
||||
for (var property in object) {
|
||||
if (object.hasOwnProperty(property)) {
|
||||
results.push(property);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
function values(object) {
|
||||
var results = [];
|
||||
for (var property in object)
|
||||
results.push(object[property]);
|
||||
return results;
|
||||
}
|
||||
|
||||
extend(Object, {
|
||||
extend:extend,
|
||||
keys:Object.keys || keys,
|
||||
values:values,
|
||||
});
|
||||
})();
|
||||
|
||||
|
||||
Object.extend(Function.prototype, (function () {
|
||||
var slice = Array.prototype.slice;
|
||||
|
||||
function update(array, args) {
|
||||
var arrayLength = array.length, length = args.length;
|
||||
while (length--) array[arrayLength + length] = args[length];
|
||||
return array;
|
||||
}
|
||||
|
||||
function merge(array, args) {
|
||||
array = slice.call(array, 0);
|
||||
return update(array, args);
|
||||
}
|
||||
|
||||
function argumentNames() {
|
||||
var names = this.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/)[1]
|
||||
.replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g, '')
|
||||
.replace(/\s+/g, '').split(',');
|
||||
return names.length == 1 && !names[0] ? [] : names;
|
||||
}
|
||||
|
||||
function bind(context) {
|
||||
if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this;
|
||||
var __method = this, args = slice.call(arguments, 1);
|
||||
return function () {
|
||||
var a = merge(args, arguments);
|
||||
return __method.apply(context, a);
|
||||
}
|
||||
}
|
||||
|
||||
function bindAsEventListener(context) {
|
||||
var __method = this, args = slice.call(arguments, 1);
|
||||
return function (event) {
|
||||
var a = update([event || window.event], args);
|
||||
return __method.apply(context, a);
|
||||
}
|
||||
}
|
||||
|
||||
function curry() {
|
||||
if (!arguments.length) return this;
|
||||
var __method = this, args = slice.call(arguments, 0);
|
||||
return function () {
|
||||
var a = merge(args, arguments);
|
||||
return __method.apply(this, a);
|
||||
}
|
||||
}
|
||||
|
||||
function delay(timeout) {
|
||||
var __method = this, args = slice.call(arguments, 1);
|
||||
timeout = timeout * 1000;
|
||||
return window.setTimeout(function () {
|
||||
return __method.apply(__method, args);
|
||||
}, timeout);
|
||||
}
|
||||
|
||||
function defer() {
|
||||
var args = update([0.01], arguments);
|
||||
return this.delay.apply(this, args);
|
||||
}
|
||||
|
||||
function wrap(wrapper) {
|
||||
var __method = this;
|
||||
return function () {
|
||||
var a = update([__method.bind(this)], arguments);
|
||||
return wrapper.apply(this, a);
|
||||
}
|
||||
}
|
||||
|
||||
function methodize() {
|
||||
if (this._methodized) return this._methodized;
|
||||
var __method = this;
|
||||
return this._methodized = function () {
|
||||
var a = update([this], arguments);
|
||||
return __method.apply(null, a);
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
argumentNames:argumentNames,
|
||||
bind:bind,
|
||||
bindAsEventListener:bindAsEventListener,
|
||||
curry:curry,
|
||||
delay:delay,
|
||||
defer:defer,
|
||||
wrap:wrap,
|
||||
methodize:methodize
|
||||
}
|
||||
})());
|
||||
|
||||
Kotlin = {}
|
||||
Kotlin.Class = Class;
|
||||
Kotlin.Namespace = Namespace;
|
||||
|
||||
Reference in New Issue
Block a user