1

I am using jQuery function .trigger( event [, extraParameters ] ) to trigger a function in a global object variable. The function runs, but with no extra parametrs, that are passed to the trigger function in an array, as the documentation says. What is wrong here?

The code: (jsfiddle)

var loc={
    connect: function(e, p1, p2) {
        console.log(p1);  //this returns undefined
        console.log(p2);  //this returns undefined
    }
}  

$(document).ready(function(){
    $(loc).trigger("connect",["a","b"]);
});

2 Answers 2

2

This one work:

function  loc(){
        /*connect: function(e, p1, p2) {
            console.log(p1);  //this returns undefined
            console.log(p2);  //this returns undefined */
        //}
        $(this).bind("connect",function(e,p1,p2){
            console.log(p1);  
            console.log(p2);
        })
    }  
    var lock = new loc();

    $(document).ready(function(){
        $(lock).trigger("connect",["a","b"]);
    });
Sign up to request clarification or add additional context in comments.

Comments

1

try:

$(loc).on('connect', function(e, param1, param2) {
    console.log(param1);
    console.log(param2);
});

Comments

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.