0
return {push:function .....在下面的代碼片段中有什麼含義。當我GOOGLE時,我發現push()方法將新項添加到數組的末尾,並返回新的長度。所以我不確定是什麼推動:它似乎是某種語法。有人能解釋我嗎?push的含義:function in javascript
function(notificationsArchive) {
var MAX_LEN = 10;
var notifications = [];
return {
push: function(notification) {
var notificationToArchive;
var newLen = notifications.unshift(notification);
//push method can rely on the closure scope now!
if (newLen > MAX_LEN) {
notificationToArchive = this.notifications.pop();
notificationsArchive.archive(notificationToArchive);
}
},
// other methods of the NotificationsService
};
它無關推帶陣列,它是由暴露模塊圖案暴露的公共方法。 – epascarello
它的屬性名稱是由作者任意選擇的 – charlietfl