开发者

how do you pass a parameter to a function when it is called by reference?

开发者 https://www.devze.com 2023-04-08 22:46 出处:网络
I\'ve created a global variable to pass informatin to a method that is called via a method reference d_g.onerror=i_bm_err_fix;

I've created a global variable to pass informatin to a method that is called via a method reference

d_g.onerror=i_bm_err_fix;

I tried passing it the variable like this(below) but it did not work.

d_g.onerror=i_bm_err_fix(d_g);

All I'm trying to do is have a generic image load if the site favicon does开发者_如何学运维 not.

function i_bm_err_fix(d_g)
  {
  d_g.src='http://www.archemarks.com/favicon1.ico';
  }

Currently I'm using a global variable to pass this info. but this does not seem like good practice.


If I understand what you're trying to do correctly, this should do the trick:

d_g.onerror = function() {
    i_bm_err_fix(d_g);
}


Wouldn't this work?

var myFunc = function(myargument){
    alert(myargument);
};

myFunc('Hello, World');
0

精彩评论

暂无评论...
验证码 换一张
取 消