so I have a class names Session
.
I declare it as:
function Session() {
}
I have a function called as: Session.prototype.parseCommand(){}
.
For some reason, if I call the function as: this.parseCommand()
it is declared as undeclared.
This also occurs with functions such as: this.textInput = false
. On some functions, I can call it, but on others it is undefined.
What is the problem?
function Session() {
this.textInput = null;
this.lineGutter = null;
}
Session.prototype.parseCommand = function(command) {
if (command === 'clear') {
} else {
var line = document.createElement('div');
line.className = 'line';
line.setAttribute('id', 'line command');
line.innerHTML = command;
document.getElementById('sessionLineGutter').appendChild(line);
}
};
Session.prototype.textInputKey = function(e) {
if (e.keyCode === 13) {
this.parseCommand(document.getElementById('sessionText').innerHTML);
e.preventDefault();
}
};
Here is the full code and the error. I also notice that I cannot use this.lineGutter.appendChild(line);
and instead I have to use document.getElementById('sessionLineGutter').appendChild(line)
. Why is this?
Thanks,