ObjectOriented JavaScript Programming by Samples

Creating New Objects using Object Literals

function initObjectsTest()
{
feli.sayMiaow();
}

var feli = 
{
    name: 'Felicitas',
    typ: 'Cat',
    sayMiaow: function ()
    {
        logMessageNEW("Miaow !");
    }  
};

Output:
8:28:35:254 Miaow !
  • Use Object Literals for Simple Objects
  • Objects created via Object Literals are Singelton Objects [ no need to implement a specific design pattern like in Java ]

 

Creating New Objects using a Constructor Function

 

Leave a Reply

Your email address will not be published. Required fields are marked *