2017-09-26 165 views
0

我想寫採用摩卡框架測試,並具備此功能需要幫助理解這個.reorder_level

this.checkReorder = function () { 
    var result = []; 
    this.products.forEach(function (p) { 
     if (p.quantity <= p.reorder_level) { 
      result.push(p) ; 
     } 
    }) 
    return result ; 
} 

我不明白的if語句

所以,如果我有這些產品

cat.addProduct(new Product("Product 1", 100, 10.00, 10 )); 
cat.addProduct(new Product("Product 2", 100, 10.00, 10)); 
cat.addProduct(new Product("Product 3", 100, 10.00, 10)); 

當我使用.reorder_level這是什麼結果呢?

+0

你不明白?它看起來像一個非常基本的條件檢查 – Steve

+0

您遍歷所有產品,爲每個項目製作一個臨時副本到「p」。然後檢查當前產品'p'的'quantity'是否與當前產品'p'的'reorder_level'相同或相同。 – lumio

+0

有什麼可以理解的,你有一些對象(p)的屬性數量和reorder_level。這也與lodash或mocha無關。它是香草js – Koborl

回答

0

我錯過了一個有解釋的頁面,對不起。