![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
How to write a function f(x) or f('x') so that it produces the same output as a call to alert-function: var x='abc'; alert('x='+x); In testing one needs to write similar alert() calls often. By having a function f(), which would add the variable name in front of the variable value one would save a lot of typing during one's lifetime. |
#3
| |||
| |||
|
|
optimistx wrote on 05 apr 2004 in comp.lang.javascript: How to write a function f(x) or f('x') so that it produces the same output as a call to alert-function: var x='abc'; alert('x='+x); In testing one needs to write similar alert() calls often. By having a function f(), which would add the variable name in front of the variable value one would save a lot of typing during one's lifetime. function toAlert(x){ alert('toAlertParameter = "'+x+'"'); } toAlert('Try me out') toAlert( 355/113) -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress) |
.
#4
| |||
| |||
|
|
By the way, is there a way to avoid eval() above? |
#5
| |||
| |||
|
|
alertt=function(){ var s=''; for (var i=0;i<arguments.length;i=i+1){ s+=arguments[i]+'='+eval(arguments[i])+'\n'; } alert(s); } snip Sorry to bother readers perhaps in vain. Hopefully the code is useful for someone else except me . |
#6
| |||
| |||
|
|
How to write a function f(x) or f('x') so that it produces the same output as a call to alert-function: var x='abc'; alert('x='+x); In testing one needs to write similar alert() calls often. By having a function f(), which would add the variable name in front of the variable value one would save a lot of typing during one's lifetime. |
#7
| |||
| |||
|
|
The code is unlikely to be of that much use to you either. |
#8
| |||
| |||
|
|
Richard Cornford wrote on 05 apr 2004 in comp.lang.javascript: The code is unlikely to be of that much use to you either. You are making a mistake here Richard. Code in this NG is not only useful for execution but also, and perhaps even more so for discussion and learning. |
|
This code as such is perhaps totally unuseful in use, but I at least learned that the window[x] form of global variables doesn't work if x is a formula. That is I did know it, otherwise it would be equally evil as eval(), but now I is in my active memory for a while. To construct a global variable name dynamicly it is very usefull: var window["varNr"+n*2] = 7*n; |
#9
| |||
| |||
|
#10
| |||
| |||
|
|
In testing one needs to write similar alert() calls often. By having a function f(), which would add the variable name in front of the variable value one would save a lot of typing during one's lifetime. |
![]() |
| Thread Tools | |
| Display Modes | |
| |