Modernize
※これから解説する内容はあくまで筆者が編み出した1つの解に過ぎません、参考、引用、反面教師如何様に受け取って頂いて構いません。私が辿ってきたJsの変遷を軽くご紹介します。
アプリケーションの定義
短くなりました。
old
(function(ns, w, d) {
ns.App = initialize;
ns.App.prototype = {
run: run
};
function initialize(options){
}
function run(){
var self = this;
}
})(this, this, document);
new
(function(ns, w, d, $) {
var app = ns.app = {};
})(this, this, document, jQuery);
その他
!=, ==- !==, ===
- グローバル変数は1つ ( app )
- for (var i = 0, max_i = array.length; i < max_i; i++) { ... }
parseInt(num)- parseInt(num, 10) or Number(num)
throw Error({})- throw { message: message }
- varはfunctionの先頭に固める