You are using chatbox in the object literal that you assign to chatbox, that doesn't work because chatbox isn't yet defined.
That uncaught error makes the execution of your entire chat.js script stop, which is why chatbox is also undefined in the following scripts.
So, beginning at line 17 of chat.js, you have to find a way to reference $chatbox in multiple places of your object.
This is a common problem in JavaScript when you would like to reference a previously defined property in an object literal.
But the thing is that you can't, so for now the quickest fix would be to declare a $chatbox variable outside of your object and reference it from inside.
Since declaring global variables left and right is definitely bad practice, this problem can be better tackled in the following 2 ways:
Constructor functions
You create a constructor function and then make instances of the object with the keyword new. This provides encapsulation of the object initialization code and allows you to create multiple chatbox objects easily if you ever need it.
function Chatbox() {
var $chatbox = $('.chatbox');
this.$chatbox = $chatbox;
this.$input = $chatbox.find('.input input');
//...
}
var chatbox = new Chatbox();
If you know you won't have multiple instances of your object though, the constructor pattern doesn't provide much and may just be an additional syntax burden, so you can use a lighter encapsulation technique:
Immediately invoked function expression (IIFE)
You put all your object initialization code in an anonymous function that returns the object at the end, and you invoke that function right in a variable declaration statement, which also provides encapsulation of any variables you need to declare when initializing your object.
var chatbox = (function() {
var $chatbox = $('.chatbox');
return {
$chatbox: $chatbox,
$input: $chatbox.find('.input input'),
// ^ This references the outer $chatbox variable, not this
// object's $chatbox property.
};
})();
chatboxis clearlyundefined, meaning your script isn't loading, or you did something wrong in it.console.login the end of your chat.js?