Fixed ECMAScript3 implementation of Kotlin.$new.
Added bind polyfill.
This commit is contained in:
@@ -12,6 +12,31 @@ var Kotlin = {};
|
||||
var emptyFunction = function () {
|
||||
};
|
||||
|
||||
if (!Function.prototype.bind) {
|
||||
Function.prototype.bind = function (oThis) {
|
||||
if (typeof this !== "function") {
|
||||
// closest thing possible to the ECMAScript 5 internal IsCallable function
|
||||
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
|
||||
}
|
||||
|
||||
var aArgs = Array.prototype.slice.call(arguments, 1),
|
||||
fToBind = this,
|
||||
fNOP = function () {
|
||||
},
|
||||
fBound = function () {
|
||||
return fToBind.apply(this instanceof fNOP && oThis
|
||||
? this
|
||||
: oThis,
|
||||
aArgs.concat(Array.prototype.slice.call(arguments)));
|
||||
};
|
||||
|
||||
fNOP.prototype = this.prototype;
|
||||
fBound.prototype = new fNOP();
|
||||
|
||||
return fBound;
|
||||
};
|
||||
}
|
||||
|
||||
Kotlin.keys = Object.keys || function (o) {
|
||||
var result = [];
|
||||
var i = 0;
|
||||
@@ -129,8 +154,14 @@ var Kotlin = {};
|
||||
|
||||
Kotlin.$createClass = Kotlin.createClass;
|
||||
|
||||
Kotlin.createObjectWithPrototype = function (prototype) {
|
||||
function C() {}
|
||||
C.prototype = prototype;
|
||||
return new C();
|
||||
};
|
||||
|
||||
Kotlin.$new = function (f) {
|
||||
var o = {'__proto__': f.prototype};
|
||||
var o = Kotlin.createObjectWithPrototype(f.prototype);
|
||||
return function () {
|
||||
f.apply(o, arguments);
|
||||
return o;
|
||||
|
||||
Reference in New Issue
Block a user