I saw javascript snippet in a book, and the writer did not declare some variables as var, the code was like this:
"use strict";
var Wingtip = window.Wingtip || {};
Wingtip.Contacts;
Wingtip.ContactList = function () {
//private members
createItem = function (lname, fname, wphone) {
},
readAll = function () {
},
readAllSuccess = function () {
},
updateItem = function (id, lname, fname, wphone) {
},
removeItem = function (id) {
},
success = function () {
readAll();
},
error = function (sender, args) {
alert(args.get_message());
}
//public interface
return {
createContact: createItem,
updateContact: updateItem,
deleteContact: removeItem
}
}();
why when creating the createItem variable the writer did not do it using var? doesnt that add the variable to the global namespace which is wrong?

0 commentaires:
Enregistrer un commentaire