I am new to javascript... I trying to create an object- \"Flower\". Every Flower has it properties: price,color,height...
Can somebody give me an idea how to build i
Here is a pattern to create object with public/private section(s)
var MyObj = function()
{
// private section
var privateColor = 'red';
function privateMethod()
{
console.log('privateMethod. The color is: ', privateColor);
}
// The public section
return
{
publicColor : 'blue',
publicMehtod: function()
{
// See the diffrent usage to 'this' keyword
console.log('publicMehtod. publicColor:', this.publicColor, ', Private color: ', privateColor);
},
setPrivateColor: function(newColor)
{
// No need for this
privateColor = newColor;
},
debug: function()
{
this.publicMehtod();
}
};
}
var obj1 = new MyObj();
obj1.publicMehtod();
obj1.setPrivateColor('Yellow');
obj1.publicMehtod();
var obj2 = new MyObj();
obj2.publicMehtod();