What is the difference between these two method styles in Javascript? Is it just an optical difference or are there more subtle differences?
Ticket.createDetailView = function(elem) {..}
Ticket = {
createDetailView: function(elem) {..}
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The first version stores the function in a new property without replacing the object in
Ticketwhile the second one creates a new object containing only one property:createDetailViewHowever assuming the object was empty in the first case there is no real difference. For example, the following two code snippets are pretty much equivalent:
and