8. General code cleanup
Old
if(!jsFrontend) { var jsFrontend = new Object(); }
jsFrontend =
{
// init something like a constructor
init: function()
{
// call functions
},
// end
eoo: true;
}
$(document).ready(jsFrontend.init);
9. General code cleanup
New
var jsFrontend =
{
// init something like a constructor
init: function()
{
// call functions
}
}
$(jsFrontend.init);
18. Variables
Scope: global
Can be referenced anywhere in the document but must be:
‣ Declared outside a function, with or without the var
keyword
19. Variables
Scope: global
Can be referenced anywhere in the document but must be:
‣ Declared outside a function, with or without the var
keyword
‣ Declared inside a function, without the var keyword, but
only once the function is called
24. Variables
Example 1
var value = 5; // gobal since we're in the global scope, outside any function
jsFrontend.faq.feedback =
{
init: function()
{
// variables
var number = 3; // local (we're already inside this anonymous function)
result = 100; // global once this function is called
var $header = $('#header'); // local (we're already inside this anonymous function)
$navigation = $('#navigation'); // global once this function is called
// bind click event
$header.on('click', function()
{
var color = 'blue'; // local
endResult = 'green'; // global once this function is called
var $body = $('body'); // local
$frame = $('#frame'); // global once this function is called
number++; // this variable is declared outside of this function's scope,
// so changes will affect not only this function's scope,
// but the declaring function's scope
// which means that this variable is "re-used" every time
});
}
}
38. jQuery 1.7
Changes
‣ New event API: .on() and .off() used for bind, live and
delegate
‣ Better HTML5 support (footer, header, section, ...)
39. jQuery 1.7
Changes
‣ New event API: .on() and .off() used for bind, live and
delegate
‣ Better HTML5 support (footer, header, section, ...)
‣ event.layerX and event.layerY
40. jQuery 1.7
Changes
‣ New event API: .on() and .off() used for bind, live and
delegate
‣ Better HTML5 support (footer, header, section, ...)
‣ event.layerX and event.layerY
‣ $.isNaN() replaced with $.isNumeric()
41. jQuery 1.7
Changes
‣ New event API: .on() and .off() used for bind, live and
delegate
‣ Better HTML5 support (footer, header, section, ...)
‣ event.layerX and event.layerY
‣ $.isNaN() replaced with $.isNumeric()
‣ $.event.proxy() use $.proxy() instead