2

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.

6
  • What does your HTML look like? Commented Feb 11, 2013 at 23:27
  • @AlienWebguy This is a simplified example. Commented Feb 11, 2013 at 23:28
  • @ExplosionPills #thing is already in the dom Commented Feb 11, 2013 at 23:29
  • I'm assuming $([e.data.func]); is what is wrong. Everything else seems fine. Commented Feb 11, 2013 at 23:30
  • why are you wrapping functions in $() ? Commented Feb 11, 2013 at 23:30

1 Answer 1

1

You're not invoking your function:

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

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

Sign up to request clarification or add additional context in comments.

2 Comments

Uncaught TypeError: Property 'func' of object #<Object> is not a function
This works... I tried it originally but I think I had my function in quote like: "differentFunction" TY

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.