次のコード:
define(function () {
var Module = function() {
$('.fixed-sidebar').each( function( index ) {
FixedSidebar.apply( this );
});
}
var FixedSidebar = function() {
var me = this;
this.hiddenStatus = true;
console.log ( this.toggle );
$($(this).find('.fixed-handler')).on('click', function() {
console.log('event passed');
//me.toggle();
//console.log ( this );
});
}
FixedSidebar.prototype = {
constructor : FixedSidebar
,toggle : function() {
if( this.hiddenStatus ) {
this.hiddenStatus = false;
$('.fixed-sidebar').animate( {
left: '-300px'
}, 1000);
} else {
this.hiddenStatus = true;
$('.fixed-sidebar').animate( {
left: '0px'
}, 1000);
}
}
};
return Module;
});
次の瞬間に JavaScript が「トグル」メソッドのプロトタイプを作成していない理由がわかりませんか?
console.log ( this.toggle ); // undefined