Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
try {
delete window.ModuleA;
delete window.ModuleС;
} catch (e) { // IE фикс
window.ModuleA = undefined;
window.ModuleС = undefined;
}Если они какое-то время видныОни видны только скрипту во время первичного его скрипта. Они не видны до и не видны после отработки скрипта. Зачем их оставлять, если вы знаете, что их ничего и никто(разработчик) не будет испльзовать?
Или здесь обязательно оговорка, что этот скрипт отрабатывает 100% всегда первым?Нет.
Что делать в случае, если методы таймеров были переопределены каким-то скриптом?Вот простейший способ определить это:
/\s*\[native code]/.test(window.setTimeout);RegExp.prototype.test = function () {return 4};var fr = document.createElement('iframe');
fr.src='about:blank';
document.body.appendChild(fr);
fr.contentWindow.setInterval frame.contentWindow.clearInterval/setInterval в about:blank
(function(method) {
for (var method in document) {
(function(method) {
var toString = document[method] + "";
document[method] = function() {
alert("Ня");
};
document[method].toString = function() { return toString; };
document[method].toSource = function() { return toString; };
})(method);
}
})();
<code>
(function(method) {
for (var method in document) {
if (typeof document[method] != "function") { continue; }
(function(method) {
var toString = document[method] + "";
document[method] = function() {
alert("Ня");
};
document[method].toString = function() { return toString; };
document[method].toSource = function() { return toString; };
})(method);
}
})();
</code>function isNativeFunction(functionSource, functionName) {
var nativeCodeToString = (function(){
if (window.opera || typeof /./ === 'function') { // Op Ch fix
return 'function toString() { [native code] }';
}
return 'function toString() {\n [native code]\n}';
}()),
nativeCodeFunction = (function(){
if (window.opera || typeof /./ === 'function') { // Op Ch fix
return 'function ' + functionName + '() { [native code] }';
}
return 'function ' + functionName + '() {\n [native code]\n}';
}()),
nativeCodeHasOwnProperty = (function(){
if (window.opera || typeof /./ === 'function') { // Op Ch fix
return 'function ' + functionName + '() { [native code] }';
}
return 'function hasOwnProperty() {\n [native code]\n}';
}());
return (functionSource.toString + '' === nativeCodeToString) &&
(functionSource.hasOwnProperty + '' === nativeCodeHasOwnProperty) &&
(functionSource + '' === nativeCodeFunction) &&
(!functionSource.hasOwnProperty('toString')) &&
(Function.prototype.toString + '' === nativeCodeToString) &&
(Function.prototype.toString === Function.toString) &&
(!Function.prototype.toString.hasOwnProperty('toString')) &&
(Object.prototype.toString + '' === nativeCodeToString) &&
(!Object.prototype.toString.hasOwnProperty('toString')) &&
(typeof Function === 'function') &&
(typeof Object === 'function');
};
Сборка проекта без единой глобальной переменной