473,387 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to call global function having its name?

Hi!

In an app which I'm trying to fix to work with FF there's a lot of
code like eval("function_name();"). I remember that there's some way
to call global functions using window object, but I can't get it to
work. Here's what I tried (in Firebug console):

function a() {alert("a called")};
a(); // works
eval("a();"); // works
window["a"](); // doesn't work
TypeError: window.a is not a function

window.b = function() {alert("b called");}
window["b"](); // works

So how can I call global functions in other way than using eval?

Thanks in advance
Feb 13 '08 #1
2 1832
On Feb 13, 9:23 am, szimek <szi...@gmail.comwrote:
In an app which I'm trying to fix to work with FF there's a lot of
code like eval("function_name();"). I remember that there's some way
to call global functions using window object, but I can't get it to
work. Here's what I tried (in Firebug console):
Running this code in the firebug console is not the same as running it
in the browser window.

Try creating a local file with your code and opening it in FF and
you'll see that it works fine.

Matt Kruse
Feb 13 '08 #2
SAM
szimek a écrit :
Hi!

In an app which I'm trying to fix to work with FF there's a lot of
code like eval("function_name();"). I remember that there's some way
to call global functions using window object, but I can't get it to
work. Here's what I tried (in Firebug console):

function a() {alert("a called")};
a(); // works
eval("a();"); // works
window["a"](); // doesn't work
?? that works with my Firefox
function b() { alert('yes ? who calls me ?'); };
window['b']();
So how can I call global functions in other way than using eval?
/* this bellow also works for me */

var a = function() { alert('yes ?'); };

window['a'](); // works

to call a function (global) :

<a href="#" onclick="a(); return false;">test</a>

Why to want more ?

--
sm
Feb 13 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

88
by: Tim Tyler | last post by:
PHP puts most of its functions into a big flat global namespace. That leads to short function names - but creates a namespace minefield for programmers. Lots of the functions are legacies from...
5
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one...
12
by: Santiago de Compostela | last post by:
Hi The following program doesn't compile on MS VC++ or Bloodshed Dev-C++ #include <iostream> int strlen(const char *in) {
8
by: lawrence | last post by:
I'm learning Javascript. I downloaded a script for study. Please tell me how the variable "loop" can have scope in the first function when it is altered in the second function? It is not defined...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
2
by: FAN | last post by:
I want to define some function in python script dynamicly and call them later, but I get some problem. I have tried the following: ################################## # code...
5
by: Rob | last post by:
Help me, I'm just beginning with programming in Access 2000. I've tried the http://www.mvps.org/access/api/api0001.htm but it won't work in Access. What am i doing wrong. I don't have...
12
by: Rahul | last post by:
Hi Everyone, I have the following code and i'm able to invoke the destructor explicitly but not the constructor. and i get a compile time error when i invoke the constructor, why is this so? ...
4
by: nickyspace | last post by:
HI all I have a little issue with this php code. Below is the code CODE: PHP 1.<?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.