Вариант 1.
var pushTheRedButton = function() {
pushTheRedButton = function() {
alert("Now look what you've done!");
}
alert("Don't ever push this button again!");
}
pushTheRedButton(); //"Don't ever push this button again!"
pushTheRedButton(); //"Now look what you've done!"
Вариант 2.
system.shutdown = function() {
system.shutdown = function() {
alert("don't worry - we're already processing your shutdown request");
}
lengthyShutdownProcess();
}
system.shutdown();
system.shutdown(); //"don't worry - we're already processing your shutdown request"
Вариант 3.
System.prototype.download = function(file) {
this.download = function() {
alert("still downloading");
}
requestDownload(file, {
callback: function() {
delete this.download;
}
});
}
Вариант 4.
var getMyText = function(myDiv) {
getMyText =
myDiv.innerText !== undefined ?
function(myDiv) {return myDiv.innerText} :
function(myDiv) {return myDiv.textContent};
return getMyText(myDiv);
}
Комментариев нет:
Отправить комментарий