私はnode.jsアプリケーションで使用しようとしているjsファイルを持っています。私は考えることができるすべてを試して、定義されていないメソッドや存在しないオブジェクトのいずれかの問題を引き続き持ちます。node.jsを使ったプロトタイプとjquery
これは私が含めてるのjsファイルです:私はこのような私のapp.jsでそれを呼んでいる
var $ = require('jquery');
var CountdownTimer = function(options){
this.settings = $.extend(
{
seconds: 60,
onTick: null,
onComplete: null
},options || {});
};
CountdownTimer.prototype = {
start: function(){
this.reset();
this.interval = window.setInterval($.proxy(this.tick, this), 1000);
},
reset: function(){
if(this.interval){
clearInterval(this.interval);
}
this.secondsRemaining = this.settings.seconds;
this.tick();
},
tick: function(){
this.hoursRemaining = Math.floor(this.secondsRemaining/(60 * 60));
this.minutesRemaining = this.secondsRemaining % (60 * 60);
this.hourMinutesRemaining = Math.floor(this.minutesRemaining/60);
this.minuteSecondsRemaining = this.minutesRemaining % 60;
this.hourSecondsRemaining = Math.ceil(this.minuteSecondsRemaining);
this.fHrs = this.formatNumber(this.hoursRemaining);
this.fMins = this.formatNumber(this.hourMinutesRemaining);
this.fSecs = this.formatNumber(this.hourSecondsRemaining);
if(this.settings.onTick){
console.log(this.settings.onTick);
this.settings.onTick();
}
if(this.secondsRemaining == 0){
this.complete();
}
this.secondsRemaining -= 1;
},
complete: function(){
clearInterval(this.interval);
if(this.settings.onComplete){
this.settings.onComplete();
}
},
formatNumber: function(n){
var s = String(n);
if(s.length == 1){
s = '0' + s;
}
return s;
}
}
module.exports = CountdownTimer;
:
var timer = new require('./countdown.js').CountdownTimer({
seconds: 80000,
onTick: function(){
//do something
},
onComplete: function(){
alert('complete');
}
});
timer.start();
私は現在取得していますエラーは次のとおりです。
TypeError: Object function (options){
this.settings = $.extend( {
seconds: 60, onTick: null, onComplete: null },options || {}); } has no method 'CountdownTimer'
私が間違っていることは何ですか?
あなたはjQuery.noConflict()を利用していますか? ? – Ohgodwhy