Shazboticus S Shazbot
Shazboticus S Shazbot

Reputation: 1289

jquery object executing object's assigned function

This is a simplified version.

If I do something like this:

var object = [{name:"bob", type:"silly", hair:"brown", func:someFunction},
              {name:"greg", type:"serious", hair:"blonde", func: differentFunction}]; 

$('#thing').bind("click", object[0], handleTranslator);

function handleTranslator(e){
    $([e.data.func]);
}

function someFunction(){
    console.log("clicking bob should trigger this function");
}

function differentFunction(){
    console.log("clicking greg should trigger this function");
}

When I click #thing, it should trigger someFunction but it doesn't. Not sure why.

Ideally, I'd like to also be able to see (console.log) my object[0] from inside someFunction.

Thanks for the help.

Upvotes: 2

Views: 79

Answers (1)

SeanCannon
SeanCannon

Reputation: 77976

You're not invoking your function:

function handleTranslator(e){
    e.data.func();
}

Demo: http://jsfiddle.net/CEdvt/

Upvotes: 1

Related Questions