var car = (function () {
var start = 13;// 起步价
var total = 0; // 总价
// 正常打车计费
return{
price: function(n) {
if (n >= 3) {
return total = start + (n - 3) * 5
} else {
return total;
}
},
// 堵车计费
yd: function(flag) {
return flag ? total + 10 : total;
}
}
})();
console.log( car.price(5));
console.log(car.yd(true));
console.log(car.price(3));
console.log(car.yd(false ));