2

下線テンプレートは、デバッガで(私はコンソールの実際のデータで遊びたい)しながら、私は<a href="http://underscorejs.org/#template" rel="nofollow noreferrer">underscore's sample template</a>コードを実行することはできませんデバッガ

// run with console open 
 
//and paste following when you hit the debugger: 
 

 
/* 
 
_.templateSettings = { 
 
    interpolate: /\{\{(.+?)\}\}/g 
 
}; 
 

 
var template = _.template("Hello {{ name }}!"); 
 

 
console.log(template({name: "Mustache"})) 
 
*/ 
 
debugger 
 
//should return: 
 
//underscore-min.js:5Uncaught TypeError: Cannot read property 'call' of undefined 
 

 
//out of debugger though, it works: 
 
_.templateSettings = { 
 
    interpolate: /\{\{(.+?)\}\}/g 
 
}; 
 
var template = _.template("Hello {{ name }}!"); 
 
console.log(template({name: "Mustache"}))
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>

では動作しません。

  1. .jsファイルのコードが正常に実行されます。 ✓
  2. ページの読み込み後にコンソールにペーストされます。 ✓
  3. デバッガブレークポイント時に貼り付けられませんでした。 ✘

    _.templateSettings = { 
        interpolate: /\{\{(.+?)\}\}/g 
    } 
    
    var template = _.template("Hello {{ name }}!"); 
    
    template({name: "Mustache"}); 
    

    エラー:

    underscore.js:1461 Uncaught TypeError: Cannot read property 'call' of undefined 
    

編集:下線バージョン1.8.3のtemplate({name: "Mustache"});

Line 1461


エラー:

var template = function(data) { 
    return render.call(this, data, _); 
}; 
+1

アンダースコアのバージョンは?貼り付けられたコードのどの行がエラーをトリガーしますか?あなたが使用しているunderscore.jsのバージョン1461はどうなっていますか? –

+0

回答(編集を参照) – Ashbury

+0

ブレークポイントはどこですか?アンダースコアの中にありますか? –

答えて

2

これはFunctionインスタンス化の症状(ライン1454をアンダースコア)であり、それは次のステートメント使用して再作成することができます。ブラウザで開いて任意のページ(でもこれ1)で

new Function('return true;') 

を、ページは現在デバッガ秒で一時停止している

function anonymous() { 
    return true; 
} 

しかし場合:それは次のように印刷されます、コンソールにこれをコピーして実行tatementはundefinedを返します。私はFirefoxで同じを実行しようとしたが、どちらも動作しません、返さない。

V8(Chrome)またはSpiderMonkey(Firefox)のJavascriptエンジンがデバッガで一時停止しているときの効果については説明できません。

あなたが本当にそれを必要とする場合は、ここでの回避策です:https://jsfiddle.net/na4Lpt7L/

var source = "Hello {{ name }}!"; 
debugger; 
var template = _.template(source); 
debugger; 

最初のブレークポイントのヒット:

> source = "Goodbye {{ name }}!"; 
< "Goodbye {{ name }}!" 

は今すぐ実行を継続し、第二のブレークポイントに:

> template({name: "Mustache"}); 
< "Goodbye Mustache!" 

いくつかのオプションを試してみたいと思うなら、それをループで貼り付けるといいでしょう(while (source.length) { ... }

+0

あなたは[video](https://vimeo.com/248018117)を見ましたか?パスワードはPasssword [ファイル](https://ufile.io/okxmk)です。ここにはデバッガはありません。ブレークポイント、または_template内のconsole.logも知っていますか? –

関連する問題

 関連する問題