party_bid 项目之 重构
function bid_result(priceLists,priceNumber){ var count = _.chain(priceLists) .sortBy("price") .groupBy(function(price){ return price.price; }) _.map(count._wrapped, function (value,key) { priceNumber.push({'price': key, 'number': value.length,'value':value}); }) save_localStorage("localStorage_bid_results",priceNumber);}function get_result(bid_results){ return _.find(bid_results,function(list) { return list.number == 1; });}
?2.面向对象编程
? javascript语言是基于原型的面向对象方式,对象依靠构造器(constructor)利用原型(prototype)构造出来的。在对数据进行增删改查等操作时,可以通过调用对象实例的方法来实现具体的操作,从而可以节省数据间的传送。??
function Activity(put){ this.title = put, this.disabled = false, this.color = "", this.bid=0}//saveActivity.prototype.save = function () { var list = Activity.get_activities(); list.unshift(this); save_localStorage("localEventsLists",list);}Activity.get_activities = function () { return JSON.parse(localStorage.getItem("localEventsLists")) || [];};?3.
?
?