Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a shorthand for document.write in JavaScript?

Tags:

javascript

in .NET you have <%= or <%: in PHP it's echo, but does JavaScript have a shorthand for document.write()?

Thanks

Mark

like image 271
Mark Sandman Avatar asked Feb 17 '26 11:02

Mark Sandman


2 Answers

No, it doesn't.

You can always:

function x (foo) { document.write(foo); } 
/* Where x is an unhelpfully short and uninformative function name */

Generally speaking, document.write should be avoided anyway. It is only useful during initial document generation and does nothing to handle special characters.

like image 121
Quentin Avatar answered Feb 18 '26 23:02

Quentin


Yes, more than one.

But "with" is considered harmful because if you make mistake to call a property that is not set you can change the value of another property or create a new global variable with that property ( more info here )

example

var d = document;
d.write('text');

with (document){
    write('text');
}
like image 35
Bakudan Avatar answered Feb 19 '26 00:02

Bakudan