Java-script object - get variable name

Posted by Mikk on Stack Overflow See other posts from Stack Overflow or by Mikk
Published on 2010-03-26T12:18:11Z Indexed on 2010/03/26 12:23 UTC
Read the original article Hit count: 281

Filed under:
|
|

Hi,

To begin with, I'm not even sure, if it is the right way to do it.

Let's say, i have script (jquery included) like this:

foo = function() {

    this.bar = function() {
    alert('I\'m bar');
    }

    this.test = function() {
    $('body').append('<a onclick="my_var.bar();">Click me</a>');
    }

this.test();

}

var my_var = new foo();

Is there any way, i could make variable "my_var" dynamic inside function "foo". So I could do something like

$('body').append('<a onclick="'+the_variable_which_im_assigned_to+'.bar();">Click me</a>');

Thank you

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about dynamic