10.增强自变量

2018-06-03  本文已影响0人  Night_LION
/**
 *  增强对象字面量
 *  解决的问题: 缩减代码
 *  
 */

// new Object(); {}
// new Array(); []

function createBookShop(inventory){
  return {
    inventory,
    inventoryValue(){
      return this.inventory.reduce((total,book) => total + book.price,0);
    },
    priceForTitle(title){
      return this.inventory.find(book => book.title === title).price;
    }
  }
}

const inventory = [
  {title:"Vue",price:10},
  {title:"Angular",price:15}
];

const bookShop = createBookShop(inventory);

// console.log(bookShop.inventoryValue());
// console.log(bookShop.priceForTitle("Angular"));


function saveFile(url,data){
  $.ajax({
    method:"POST",
    url:url,
    data:data
  });
}

const url = "http://fileupload.com";
const data = {color:"red"};

saveFile(url,data);









 



 



 
上一篇下一篇

猜你喜欢

热点阅读