JSFiddle - React, Tailwind, and code Playground
by William Sena
HTML
<p>
Ok
</p>
Babel + JSX
function notifyClient(message) {
alert(message);
}
function sendMail(customer, total) {
notifyClient.call(this, 'TODO: Send mail, (' + String(customer.id) + ', ' + String(total) + ')');
}
function getDeals() {
var product = arguments[1];
var minPrice = arguments[2];
product.price = Math.round(product.price * 0.9, 2);
if(product.price < minPrice) {
product.price = minPrice;
}
}
function ShopCart(){
}
ShopCart.prototype.items = [];
ShopCart.prototype.customer = { id: 1 };
ShopCart.prototype.total = function total() {
var total = 0;
var item;
for(var i=0, c=this.items.length; i<c; i++){
item = this.items[i];
total += item.price * item.quantity;
}
return total;
};
ShopCart.prototype.addItem = function addItem(product) {
this.getDealsByProduct(product);
this.items.push(product);
notifyClient.call(this, 'Item added ' + product.name);
};
ShopCart.prototype.getDealsByProduct = function getDealsByProduct(product) {
getDeals.apply(this, [product, product.price * 0.6]);
};
ShopCart.prototype.placeOrder = function placeOrder() {
sendMail.apply(this, [this.customer, this.total()]);
};
var shopCart = new ShopCart();
shopCart.addItem({
id: 1,
name: 'Xbox Game',
price: 179,
quantity: 1
});
shopCart.placeOrder();