function Product(name,price) { this.name = name; this.price = price; //this.discount = 0; // <- remove this line and refactor with the code below var _discount; // private member Object.defineProperty(this,"discount",{ get: function() { return _discount; }, set: function(value) { _discount = value; if(_discount>80) _discount = 80; } }); } // the client code var sneakers = new Product("Sneakers",20); sneakers.discount = 50; // 50, setter is called sneakers.discount+= 20; // 70, setter is called sneakers.discount+= 20; // 80, not 90! alert(sneakers.discount); // getter is called
mProductArrayList.add(new Product("a", 100)); mProductArrayList.add(new Product("b", 200)); mProductArrayList.add(new Product("c", 300)); mProductArrayList.add(new Product("d", 400)); mProductArrayList.add(new Product("e", 500)); mProductArrayList.add(new Product("f", 600)); mProductArrayList.add(new Product("g", 700)); mProductArrayList.add(new Product("h", 800)); mProductArrayList.add(new Product("i", 900)); mProductArrayList.add(new Product("j", 1000)); mProductArrayList.add(new Product("k", 1100)); mProductArrayList.add(new Product("l", 1200)); mProductArrayList.add(new Product("m", 1000)); mProductArrayList.add(new Product("n", 1300)); mProductArrayList.add(new Product("o", 1400)); mProductArrayList.add(new Product("p", 1500));
new Product( "Electric Guitar", "http://images.example/electric-guitar.jpg", 100)); products.add( new Product( "Electric Train", "http://images.example/train.jpg", 100)); products.add( new Product( "Acoustic Guitar", "http://images.example/acoustic-guitar.jpg", 80)); products.add( new Product( "Guarana Soda", "http://images.example/soda.jpg",
var Product = Parse.Object.extend("product"); var newProduct = new Product(); var productName = "Temp4Product"; newProduct.set("name",productName); newProduct.set("name_lowercase",productName.toLowerCase()); newProduct.save();
function Product(sku) { Object.defineProperty(this, "sku", { get: function() { return sku;}, writable: false, // default value, doesn't have to be specified configurable: false, // default value, doesn't have to be specified enumerable: false }); } var p = new Product(1234); console.log(p.sku);
var items = [ new Product({ Name: "Crystalys", SKU: "00001", Price: 500, Stocks: 12, Quantity: 0 }), new Product({ ...
var a = new Product(); var b = new Product_dept(); a instanceof Product // true a instanceof Product_dept // false b instanceof Product // true b instanceof Product_dept // true
function Product(sku) { this.getSku = function() { return sku; } } var p = new Product(1234); console.log(p.getSku());
@Test public void testsTotalPriceAsSumOfProductPrices() { Products products = new Products(); // Or any appropriate constructor products.add(new Product("first", 10)); // Assuming such a constructor exists products.add(new Product("second", 20)); products.add(new Product("second", 30)); assertEquals("Sum must be eq to 60", 60, products.getTotalPrice()); }
Product product = new Product(); product.Name = "Apple"; product.Expiry = new DateTime(2008, 12, 28); product.Price = 3.99M; product.Sizes = new string[] { "Small", "Medium", "Large" }; string output = JsonConvert.SerializeObject(product);
List<Product> productList = new ArrayList<Product>(); while (products.next()) { int prodId = products .getInt("id"); String prodName = products .getString("name"); Product product = new Product(prodId, prodName); productList.add(product); }
for(int i = 0; i < range; i++) { productRange[i] = new Product(); productRange[i].setProductCode(codeDataScan.next()); productRange[i].setPricePerUnit(Integer. parseInt(priceDataScan.nextLine())); }
@Test public void TargetAdapterReturnsProducts() { List<Product> data = new ArrayList<Product>(); data.add(new Product("Sample Product 1")); data.add(new Product("Sample Product 2")); data.add(new Product("Sample Product 3")); TargetAdapter adapter = new TargetAdapter(new ProductsDatasource(data)); // See the dependency List<Product> products = adapter.products(); Assert.assertNotNull(adapter); Assert.assertTrue(products.size() == 3); }
Product pr1 = new Product("str1", "str1", "str1", 250); Product pr2 = new Product("str2", "str2", "str2", 200); List<Product> list = new ArrayList<Product>(); list.add(pr1); list.add(pr2); Map<String, List<Product>> map = new HashMap<String, List<Product>>(); map.put("order_item", list); System.out.println(new Gson().toJson(map));
@Test(expected = WrongCostFormat.class) public void shouldThrowNumberFormatException() { Product p = new Product(); p.checkAndReturnDoubleIfOk("1.234"); }
Customer customer = new Customer(); Product product = new Product(); // Set your values ... Gson gson = new Gson(); String json = gson.toJson(); Curtomer deserialized = gson.fromJson(json, Customer.class);
if (resultSet!= null) { while (resultSet.next()) { Product product = new Product(); product.setProductId(resultSet.getInt("productId")); product.setProductName(resultSet.getString("productName")); productList.add(product); } request.setAttribute("productList", productList); RequestDispatcher rd = request.getRequestDispatcher("adminViewSearch.jsp"); rd.forward(request, response); }