I'm trying to understand the finer points of JS and am seeing many examples of object literals being passed into constructors. What are the benefits of this approach and how would I create my object to use this approach?
For example:
myTooltip = new YAHOO.widget.Tooltip("myTooltip", {
context: "myContextEl",
text: "You have hovered over myContextEl.",
showDelay: 500
});
Suppose I was creating a simple class. Many simple OO tutorials suggest something like
myCat = new Cat();
myCat.name = "fluffy";
myCat.friendly = true;
myCat.lives = 9
As opposed to
myCat = new Cat({
name: "fluffy",
friendly:true,
lives: 9
})
How do I create the Cat object to use this approach?