Clara: Vereinfachte Schreibweise für JS

Beitrag lesen

var dc = function(str){

document.write(str);
};

dc("hallo");


>   
> Wozu eine Funktion drumherum basteln?  
>   
> ~~~javascript

var w = document.write;  

> w("I know I should probably not be using document.write in the first place.");

Schon mal ausprobiert und in die Fehlermeldungen des Browsers geschaut? Wenn du write() aus document "rausnimmst", nimmst du ihm auch seinen Kontext: "TypeError: 'write' called on an object that does not implement interface HTMLDocument."

So würde das was werden …

var w = document.write;  
w.call(document, "I know I should probably not be using document.write in the first place.");

… aber damit sind wir letztlich wieder bei der Ausgangsfrage.