mirror of
https://github.com/Doodle3D/Doodle3D-API
synced 2024-12-23 22:13:48 +01:00
28 lines
709 B
JavaScript
28 lines
709 B
JavaScript
|
/* */
|
||
|
var $ = require("./$"),
|
||
|
tpl = String({}.hasOwnProperty),
|
||
|
SRC = require("./$.uid").safe('src'),
|
||
|
_toString = Function.toString;
|
||
|
function $redef(O, key, val, safe) {
|
||
|
if ($.isFunction(val)) {
|
||
|
var base = O[key];
|
||
|
$.hide(val, SRC, base ? String(base) : tpl.replace(/hasOwnProperty/, String(key)));
|
||
|
if (!('name' in val))
|
||
|
val.name = key;
|
||
|
}
|
||
|
if (O === $.g) {
|
||
|
O[key] = val;
|
||
|
} else {
|
||
|
if (!safe)
|
||
|
delete O[key];
|
||
|
$.hide(O, key, val);
|
||
|
}
|
||
|
}
|
||
|
$redef(Function.prototype, 'toString', function toString() {
|
||
|
return $.has(this, SRC) ? this[SRC] : _toString.call(this);
|
||
|
});
|
||
|
$.core.inspectSource = function(it) {
|
||
|
return _toString.call(it);
|
||
|
};
|
||
|
module.exports = $redef;
|