Преобразование списка функций в порядок, так что это ООП. В настоящее время у меня есть класс shoppingCart. Внутри shoppingCart у нас есть; сохранять, загружать, удалять и т. д., а не обращаться к нему.Создание функции в Javascript OOP
a) Правильно ли это написано в ООП б) Как вы получаете доступ к определенным функциям.
JS
var cart = [];
function shoppingCart() {
//var Item = function(title, description, price, image_url, count) {
this.newitem = function(title, description, price, image_url, count) {
this.title = title
this.description = description
this.price = price
this.image_url = image_url
this.count = count
}
//function addIteamToCart(title, description, price,image_url, count){
this.addNewitem = function addIteamToCart(title, description, price, image_url, count) {
for (var i in cart) {
console.log(cart);
if (cart[i].title === title) {
cart[i].count += count;
return;
}
}
var item = new Item(title, description, price, image_url, count);
console.log(item);
cart.push(item);
saveCart();
}
};
console.log(shoppingCart.newitem(sss,ddd,zzz,sss));
Конструктор 'Item' должен находиться за пределами конструктора' shoppingCart'. Никогда не гнечивайте классы в JS! – Bergi