Javascript undefined class function when missing semicolon -
function foo() { var = this; that.bar = function() {} that.baz = function() {} (function() { that.baz(); }()); } new foo; uncaught typeerror: object #<foo> has no method 'baz'
that.bar works fine, it's last function doesn't exist. adding ; after baz function definition fixes everything.
i know excluding ; can mess things up, thought sure you're not supposed put ; after functions. no language that. why excluding ; after baz function cause break? should putting ; after function definitions?
you don't need semicolon after function declaration:
function foo() { } there no harm done if add semicolon, don't need it:
function foo() { }; that inserts empty statement after function declaration, has no effect. in same way, no harm, other confusing people read code:
var = 1;;;;;;;;;;;;;;;;;;;;;;;;;; otoh, do need semicolon after assignment statement:
that.prop = 1; and doesn't change if value you're assigning function expression:
that.foo = function() {};
Comments
Post a Comment