undefined is not a function【Handlebars】
問題
- handlebars使ってて掲題のエラー出た
"undefined is not a function" とは
- ご存知、未定義の変数を関数呼び出しした時に起きるエラー
var my = { foo: function() { console.log("This is my.foo!"); } /* bar: function() { console.log("This is my.bar, undefined!!"); } */ }; var foo = my["foo"]; foo(); // This is my.foo! var bar = my["bar"]; bar(); // TypeError: undefined is not a function
調査
- 上記ではapp.jsの2212行目でエラーが出ているので見に行く
2210 return function(context, options) { 2211 options = options || {}; 2212 var result = templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data); 2213
debugger
など仕込むと、どうやらこのtemplateSpec
がFunction
オブジェクトではないので、call
メソッドが無いっぽい
さらに調査
「Handlebarsのバージョンが古いんじゃねえの?」とのご指摘
解決
--- a/bower.json +++ b/bower.json @@ -4,6 +4,6 @@ "dependencies": { "showv": "https://github.com/otiai10/showv.git", "jquery": "1.10.1", - "handlebars": "1.0.0" + "handlebars": "2.0.0" } }
DRYな備忘録として