The property method can contain parameters:
Copy codeThe Code is as follows:
Function ClassX (name ){
This. name = name;
ClassX. prototype. show = function (param ){
Alert (this. name + "" + param );
};
}
Var o = new ClassX ("name ");
O. show ("param"); // name param
However, although the above is a reference defined directly in the function signature, if you do not call o. show ('param') is not necessarily useful when it is passed in through callback of other functions, because when someone else calls this method, it is not necessarily passed in to you, for example, when using ajax
Request. onreadystatechange = function (param ){...}
Or
Request. onreadystatechange = callBack; function callBack (param ){...}
This is difficult, because ajax does not pass the param parameter to you at this time. The correct method is as follows:
Copy codeThe Code is as follows:
// Request. onreadystatechange = orgEval; // Error Method
// Request. onreadystatechange = function (request, pOrgName) {// Error Method
// OrgEval (request, pOrgName );
//};
//...
Request. onreadystatechange = function () {// correct practice
OrgEval (request, pOrgName); // call the callback implementation in the anonymous function and directly pass in the parameter. The closure nature of JavaScript is used here.
};
//...
Function orgEval (req, orgName ){
//...
}
In this way, you can call the callback implementation function in an anonymous function and directly input parameters.