var INGRIDIENTS = {
'cheese': {
weigth: 50,
calories: 50
},
'sauce': {
weight: 10,
calories: 20
},
'mozzarela': {
weigth: 25,
calories: 25
},
'peperoni': {
weight: 20,
calories: 20
}
}
function Pizza(recipe) {
// правила создания объекта - его инициализация
// this который доступен в этой функции - это новый объект, который будет создан если функцию вызвать с new
this.base = options.base
this.ingridients = recipe.ingridients
}
Pizza.prototype = { // or Object.create
getWeight: function() { // 'эта функция называется метод объекта
// this такой же как в функции-конструкторе
// мы можем из него брать любые свойства
return this.weight
},
getCalories: function() {
return this.calories
}
}
// creating objects
var recipeMargarita = {
base: {
weight: 100,
calories: 30
},
ingridients: [
INGRIDIENTS.cheese,
INGRIDIENTS.sauce,
INGRIDIENTS.mozzarela
]
}
var pizza = new Pizza(recipeMargarita)
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.