safaribook-knockout-essentials/ko-cart/js/models/Product.js

19 lines
422 B
JavaScript
Raw Normal View History

"use strict";
var Product = function (id, name, price, stock) {
"use strict";
var _id = ko.observable(id),
_name = ko.observable(name),
_price = ko.observable(price),
_stock = ko.observable(stock);
var _lineColor = ko.computed(function() {
return (_stock() < 5) ? 'red' : 'black';
});
return {
id: _id,
name: _name,
price: _price,
stock: _stock,
lineColor: _lineColor
};
};