I am new to javascript, so forgive me for asking such a novice question. I have been trying to learn the javascript language by looking at SPA examples that use the following libraries durandal, knockout js & breeze js, sammy & require and am trying to use the Module pattern, I think.
I have come across different code syntax as follows
define(['services/logger'], function (logger) {
var model = "somedata"
var vm = {
activate: activate,
title: 'Details View'
};
return vm;
function activate() {
logger.log('Details View Activated', null, 'details', true);
return true;
}
});
and
define(['services/logger'], function (logger) {
var model = "somedata"
return {
activate: activate,
title: 'Details View'
};
function activate() {
logger.log('Details View Activated', null, 'details', true);
return true;
}
});
my questions are
- Is there an advantage to using one syntax over the over?
- Will the variable "model" in the code block above have a global scope?
- What is the best way to access the "title" variable from within functions? should I use this.title?
Thank you in advance.