Javascript: understanding the syntax of functions and parameters

I am trying to understand the event onchange bootstrap-multiselect. In particular, I am trying to understand the function syntax and parameters.

$('#example-onChange').multiselect({
     onChange: function(option, checked, select) {
            alert('Changed option ' + $(option).val() + '.');
           }
});

How to find out what three parameters in a function mean? Where will I get these three parameters? I also tried looking at the code https://github.com/davidstutz/bootstrap-multiselect/blob/master/dist/js/bootstrap-multiselect.js#L263 , but couldn't push it.

I know that with the warnings that the function in this option refers to the selected option, it checkedshows whether the option was checkedor unchecked. I keep getting undefinedwhen executed console.log(select)inside a function, so I'm not sure what that means.

Question . How to understand function parameters and syntax like these? This is just an example, but knowing the general procedure will help me decode other similar functions in the future.

+4
source share
2 answers

In short, it seems that the library does not actually provide a parameter select.


In general, in situations where the documentation is not very accurate, the method that I often use is to console.log argumentscheck what each one looks like.

In this situation, when executed:

$('#example-onChange').multiselect({
    onChange: function(option, checked, select) {
        console.log(arguments);
    }
});

... I got the following result:

enter image description here

... from this you can see two arguments. The first is the jQuery object that was clicked. The second (you can assume) is logical as to whether the option is selected or not.

, select ( ) .


, , - , ; , , , . onChange , , onChange 3 .

... . 3 , ( ) , .


, :

  • ( " " , debugger), , ( , ), , .

  • GitHub. .

+3

, Javascript .

, Javascript , . .

, , , . , , . - , .

, , , # example-onChange, (onChange).

1:

onClose:function(success)
{
    //TODO
}

"" : true, , "" .

2:

afterSave: (, ) {

}

"filename" .

, , , .

+1

All Articles