I’m making a JavaScript object with literal notation, but I’m not sure how to make the object receive parameters like this:
hi.say({title: "foo", body: "bar"});
instead of hi.say("foo", "bar");.
Current code:
var hi = {
say: function (title, body) {
alert(title + "\n" + body);
}
};
The reason why I want that is because I want people to be able to skip the title and just put the body, and do the same for many other parameters.
So that’s why I need something like how we can use jQuery functions’ parameters {parameter:"yay", parameter:"nice"}
P.S. I’m open too for modification of the current method – keeping in mind that there would be many parameters, some required and some optional, and which cannot be ordered in a specific way.