目前我正在学习角度JS,但我认为这个问题与javascript有关。首先我做了我的代码(正如教程所说的那样),然后,当我进入下一个级别时,我看到了不同的东西。
教程说:
“创建一个设置this.current var的函数,但是当没有传递值时,将其设置为0”。
而我,我所有的“高尚”都做到了,并且它起作用了:
app.controller('GalleryController', function(){
this.current = 0;
this.setCurrent = function(newGallery){
if(newGallery === null){
this.current = 0;
return;
}
this.current = newGallery;
};
});
这就是我之前看到的:
app.controller('GalleryController', function(){
this.current = 0;
this.setCurrent = function(newGallery){
this.current = newGallery || 0;
};
});
我在问什么,它是如何工作的以及它为何起作用。因为它只是一个OR运算符
感谢。