Probably because you didn't assign RegisterCode a value when you defined the class, So when testFunction is called, RegisterCode is null
Problem: MSScriptControl.AddCode Prompt: Cannot perform runtime binding on null references
Scenario: Load the js file in asmx.cs file by MSScriptControl.AddCode and call InitProcess function in the js file.
High probability and js internal content has a ip, if the js content is a function: function InitProcess(InputCode){return "hello" + InputCode; } No problem.
Error occurs when the js content is changed to:
function InitProcess(InputCode)
{
` ` ` < br / > / class definition < br / > function RegisterClass < br / > {< br / > var Code;
var Type;
this.testFunction = function(code)
{
return "hello" + code;
};
}
// Ends the class definition and starts calling
var objRegister = new RegisterClass();
objRegister.testFunction(InputCode);
javascript
For the first time, with javascript, do not understand what the problem is?
0 Answer
Probably because you didn't assign RegisterCode a value when you defined the class, So when testFunction is called, RegisterCode is null
Thank you for your answer, I test class should be recognizable as follows:
function RegisterClass()
{
var RegisterCode;
var Type;
this.testFunction = function(){
return "hello~~ " + RegisterCode;
}
function AutoReg(code)
{
return "hello~~ " + RegisterCode;
}
}
function InitProcess(InputCode)
{
var objRegister = new RegisterClass();
objRegister.RegisterCode = InputCode;
//return "null~~" + objRegister.RegisterCode; Here is the value of the member that can be printed, so the sense class recognizes
objRegister.testFunction();
//objRegister.AutoReg(InputCode); // Because it is a private method, this call will prompt you that the property or method is missing.
}
}
//类定义结束,开始调用
var objRegister = new RegisterClass();
return objRegister.testFunction(InputCode);
This problem may be caused by the MSScriptControl.AddCode method not recognizing classes defined in js......
suggests that you change the class definition in js to a function definition, or use other methods to load the js file, such as using the XMLHttpRequest object, such as using the class keyword in ES6.
这家伙很懒,什么都没留下...