mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Change Bootstrap core so no standard prototypes are modified, not even Function.prototype.
This commit is contained in:
parent
7355c2d4a7
commit
84790780e3
1 changed files with 30 additions and 34 deletions
64
lib/bootstrap.js
vendored
64
lib/bootstrap.js
vendored
|
@ -69,12 +69,18 @@ var Base = new function() {
|
|||
if (func) {
|
||||
if (prev && /\bthis\.base\b/.test(val)) {
|
||||
var fromBase = base && base[name] == prev;
|
||||
res = (function() {
|
||||
res = function() {
|
||||
var tmp = describe(this, 'base');
|
||||
define(this, 'base', { value: fromBase ? base[name] : prev, configurable: true });
|
||||
try { return val.apply(this, arguments); }
|
||||
finally { tmp ? define(this, 'base', tmp) : delete this.base; }
|
||||
}).pretend(val);
|
||||
};
|
||||
res.toString = function() {
|
||||
return val.toString();
|
||||
}
|
||||
res.valueOf = function() {
|
||||
return val.valueOf();
|
||||
}
|
||||
}
|
||||
if (beans && (bean = name.match(/^(get|is)(([A-Z])(.*))$/)))
|
||||
beans.push([ bean[3].toLowerCase() + bean[4], bean[2] ]);
|
||||
|
@ -119,37 +125,6 @@ var Base = new function() {
|
|||
return ctor;
|
||||
}
|
||||
|
||||
inject(Function.prototype, {
|
||||
inject: function(src) {
|
||||
if (src) {
|
||||
var proto = this.prototype, base = proto.__proto__ && proto.__proto__.constructor;
|
||||
inject(proto, src, false, base && base.prototype, src.preserve, src.generics && this);
|
||||
inject(this, src.statics, true, base, src.preserve);
|
||||
}
|
||||
for (var i = 1, l = arguments.length; i < l; i++)
|
||||
this.inject(arguments[i]);
|
||||
return this;
|
||||
},
|
||||
|
||||
extend: function(src) {
|
||||
var proto = new this(this.dont), ctor = extend(proto);
|
||||
define(proto, 'constructor', { value: ctor, writable: true, configurable: true });
|
||||
ctor.dont = {};
|
||||
inject(ctor, this, true);
|
||||
return arguments.length ? this.inject.apply(ctor, arguments) : ctor;
|
||||
},
|
||||
|
||||
pretend: function(fn) {
|
||||
this.toString = function() {
|
||||
return fn.toString();
|
||||
}
|
||||
this.valueOf = function() {
|
||||
return fn.valueOf();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
||||
function each(iter, bind) {
|
||||
var bind = bind || this, iter = iterator(iter);
|
||||
try {
|
||||
|
@ -180,7 +155,28 @@ var Base = new function() {
|
|||
}, new obj.constructor());
|
||||
}
|
||||
|
||||
return Object.extend({
|
||||
function Base() {}
|
||||
|
||||
Base.inject = function(src) {
|
||||
if (src) {
|
||||
var proto = this.prototype, base = proto.__proto__ && proto.__proto__.constructor;
|
||||
inject(proto, src, false, base && base.prototype, src.preserve, src.generics && this);
|
||||
inject(this, src.statics, true, base, src.preserve);
|
||||
}
|
||||
for (var i = 1, l = arguments.length; i < l; i++)
|
||||
this.inject(arguments[i]);
|
||||
return this;
|
||||
};
|
||||
|
||||
Base.extend = function(src) {
|
||||
var proto = new this(this.dont), ctor = extend(proto);
|
||||
define(proto, 'constructor', { value: ctor, writable: true, configurable: true });
|
||||
ctor.dont = {};
|
||||
inject(ctor, this, true);
|
||||
return arguments.length ? this.inject.apply(ctor, arguments) : ctor;
|
||||
};
|
||||
|
||||
return Base.inject({
|
||||
has: has,
|
||||
each: each,
|
||||
|
||||
|
|
Loading…
Reference in a new issue