There is a code that on this line of code
Boo.prototype.initone (a) { <-- Syntax error
I want to create a simple object of Boo with one property this.bar why would this be giving me an error? The error is listed below which is an uncaught Syntax Error but I am not seeing it.
I know that syntax errors should not be posted but I am just not seeing what is completely wrong with this code below.
Error Code Here:
Boo.prototype.initone (a) {
this.bar = a;
return this;
}
Error
Uncaught SyntaxError: Unexpected token {
Code:
<script>
function Test1() {
}
function Boo () {
this.bar = 'Test This Method';
}
Boo.prototype.initone (a) {
this.bar = a;
return this;
}
Boo.prototype.inittwo (b) {
this.bar = 'something to do with ' + b;
return this;
}
var a = new Boo().initone('constructor 1');
var b = new Boo().inittwo('constructor 2');
</script>
Code: This code will still show an uncaught exception. If I take the return this out then no error will occur on initone but inittwo seems to be ok.
Boo.prototype.initone = function (a) {
this.bar = a;
return this;
}
Boo.prototype.inittwo = function (b) {
this.bar = 'something to do with ' + b;
return this;
}
Boo.prototype.initone = function(a) {Boo.prototype.initone (a) { }would define a function?thisto benullorundefined, which would result in a TypeError.returncertainly won't be a SyntaxError.