Like the Title i want to make a method(in this case 'addItem') same as this one but accepting one more parameter
(function (){return{
addItem : function (type, des, val) {
var newItem, ID;
ID = dataStructure.allItems[type][dataStructure.allItems[type].length - 1].id + 1;
if (dataStructure.allItems[type].length > 0){
ID = dataStructure.allItems[type][dataStructure.allItems[type].length - 1].id + 1
}else {
ID = 0;
}
//Create new ELEMENT based on 'exp' or 'inc' type
if (type === 'exp'){
newItem = new Expense(ID, des, val);
}else if (type === 'inc'){
newItem = new Income(ID, des, val);
}
//Push it into our data structure
dataStructure.allItems[type].push(newItem)
//Return the new element
return newItem;
}
};})();
I want to call( depending on some inputs) a method('addItem') from an object or invoke the other if the value of the input is 'X' .
Aucun commentaire:
Enregistrer un commentaire