我有以下 JS 片段
var Customer : function()
{
this.ShipProduct : function()
{
//Logic for shipping product. If shipping successful, notify user
//Here I am trying to call Notify
//this.Notify(); // does not work
}
this.Notify = function()
{
//Logic for notify
}
}
我如何从 ShipProduct 调用 Notify?
最佳答案
那不是 JS,那是语法错误的集合。
赋值变量时使用=
,简单对象内使用:
,不要混淆简单对象和函数,不要忘记逗号,不要在属性前面加上前缀带有 this.
.
var Customer = {
ShipProduct : function()
{
//Logic for shipping product. If shipping successful, notify user
//Here I am trying to call Notify
this.Notify(); // this does work
},
Notify: function()
{
//Logic for notify
}
}
Customer.ShipProduct();
关于javascript - 在 JS 中从一个方法调用另一个方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3535304/