Nic*_*ick 0 javascript javascript-framework javascript-objects
我有以下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
}
}
Run Code Online (Sandbox Code Playgroud)
我如何从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();
Run Code Online (Sandbox Code Playgroud)