У меня есть mainoops.js файл, который имеет следующий кодJavascript объект класса не определен Ошибка
var Notifier = function(){
this.socket = io.connect('http://localhost:8080');
this.currentdate = new Date();
}
Notifier.prototype.addCbNotification = function(message){
var datetime = this.currentdate.getDate() + "/" + (this.currentdate.getMonth()+1) + "/" + this.currentdate.getFullYear() + " @ " + currentdate.getHours() + ":" + currentdate.getMinutes() + ":" + currentdate.getSeconds();
var datamessage = " <div class='row'><div class='col-xs-2'><i class='fa fa-envelope'></i></div><div class='col-xs-10'><h5><a href=''>" + message + "</a></h5><small>"+datetime+"</small></div></div>";
$("#callback-btn").addClass('alert-notice');
$("#callback").append("<li class='list-group-item unread'>"+datamessage+" </li> ");
}
Notifier.prototype.addNotification = function(message){
var datetime = currentdate.getDate() + "/" + (currentdate.getMonth()+1) + "/" + currentdate.getFullYear() + " @ " + currentdate.getHours() + ":" + currentdate.getMinutes() + ":" + currentdate.getSeconds();
var datamessage = " <div class='row'><div class='col-xs-2'><i class='fa fa-envelope'></i></div><div class='col-xs-10'><h5><a href=''>" + message + "</a></h5><small>"+datetime+"</small></div></div>";
$("#notice-btn").addClass('alert-notice');
$("#notice").append("<li class='list-group-item unread'>"+datamessage+" </li> ");
}
Notifier.prototype.startsocketforcallbback = function(myid) {
// body...
socket.on('callback', function (data) {
var message = data.split("_");
if(myid.toLowerCase().trim() == message[0].toLowerCase().trim()){
this.addCbNotification(message[1]);
}
});
};
Notifier.prototype.startsocketfornotice = function() {
// body...
socket.on('notice', function (data) {
var message = data.split("_");
if(myid.toLowerCase().trim() == message[0].toLowerCase().trim()){
this.addNotification(message[1]);
}
});
};
Я зову его в моем файле PHP, как следовать
<script src="{{asset('/js/mainoops.js')}}"></script>
Но когда я пытаюсь создать его экземпляр в странице PHP как этот
<script>
var obj = new Notifier();
obj.startsocketforcallbback('<?php echo Auth::user()->empid; ?>');
obj.startsocketfornotice();
</script>
я получаю следующее ERROR
Uncaught ReferenceError: Notifier is not defined
Пожалуйста, дайте причину Вниз голосования благодаря – Vikram