バックボーンにビューがあり、いくつかの属性を作成したいと考えています。
私はそれをしました:
var ProgrammeDetailsView = Backbone.View.extend({
$infoResult: $('#info-result'),
$castingResult: $('#casting-result'),
$broadcastResult: $('#broadcast-result'),
$testResult: $('#test'),
[...]
そして、驚いたことに、次の結果が得られました。
console.log(this.$infoResult); -> Array { selector="#test", forEach=forEach(), reduce=reduce(), more...}
ご覧のとおり、ID「#info-result」を持つオブジェクトを返す「this.$infoResult」を使用しましたが、実際には返されるのは最新の変数です。
私がそれを行う場合:
var ProgrammeDetailsView = Backbone.View.extend({
$infoResult: '#info-result',
$castingResult: '#casting-result',
$broadcastResult: '#broadcast-result',
$testResult: '#test',
問題ありません。参照:
console.log(this.$infoResult); -> "#info-result"
理由はわかりますか?