In a page I create an instance of a class (MyClass)
, this class has 2 methods. But I d like to do 2 things :
- In (1), set the value
this.message
- In (2), call the information method or another method of the class
感谢
<script type="text/javascript">
$(document).ready(function () {
var myClass = new MyClass("MyParam");
$( #Target ).click(function (event) {
myClass.save("Test");
});
});
</script>
function MyClass(myParam) {
this.myParam = myParam;
this.isError = false;
this.message = "";
}
// Define the class methods.
MyClass.prototype = {
save: function (action) {
**(2)**
},
information: function (action) {
**(1)**
}
};
<>Update1>
在我执行以下编码时,< 编码> > > 编码> 数值载于<代码>。
MyClass.prototype = {
click: function (action) {
var myData;
$.post(....., $("form").serialize(),
function (data) {
myData = data;
});
this.isError = this.information(myData);
},
information: function (data) {
alert(data);
return true;
}
};