Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #28698

Is it possible to reassign js function to an object without including parameter(s)?

Newsgroups comp.lang.javascript
Date 2015-09-20 07:06 -0700
Message-ID <40bb4feb-2cbf-4b11-86b5-4f845eee6ca8@googlegroups.com> (permalink)
Subject Is it possible to reassign js function to an object without including parameter(s)?
From justaguy <lichunshen84@gmail.com>

Show all headers | View raw


Hi,

I have some js functions with one parameter and would like to re-assign a function to another object.  For instance,
function f1(p1)
{
window.open('myscript.html?'+p1);
}

function f2(p2)
{
window.open('myscript2.html?'+p2);
}

The HTML file may read like this:
<span id="me1" onclick="f1(p1)">stuff 1</span>
<span id="me2" onclick="f2(p2)">stuff 2</span>

Now, say, I want to reassign f2 to the object id of me1 on-the-fly and p2 value is unknown to me yet, simple reassignment:
document.getElementById('me1').onclick = f2;  // won't work.
and yet, I can't re-assign like this:
document.getElementById('me1').onclick = f2(p2); // because p2 value is unknown yet.

How to accomplish the above if doable? Or another way to tackle it? Thanks. 

Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Is it possible to reassign js function to an object without including parameter(s)? justaguy <lichunshen84@gmail.com> - 2015-09-20 07:06 -0700
  Re: Is it possible to reassign js function to an object without including parameter(s)? Martin Honnen <mahotrash@yahoo.de> - 2015-09-20 16:42 +0200
    Re: Is it possible to reassign js function to an object without including parameter(s)? justaguy <lichunshen84@gmail.com> - 2015-09-20 08:58 -0700
  Re: Is it possible to reassign js function to an object without including parameter(s)? danny <dann90038@gmail.com> - 2015-09-24 13:03 -0700
    Re: Is it possible to reassign js function to an object without including parameter(s)? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-09-25 09:11 +0200

csiph-web