Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

javascript in another file

10 views
Skip to first unread message

jags

unread,
Aug 29, 2012, 1:14:41 PM8/29/12
to
i am trying to do like this


js file


var myvar =
{
myfunc1: function {},
myfunc2: function{}
};

in html file i include this script through src

then on body onload i call myvar.myfunc1;

in crome dev console i see error near var, why so ?

Stefan Weiss

unread,
Aug 29, 2012, 4:38:54 PM8/29/12
to
On 2012-08-29 19:14, jags wrote:
> var myvar =
> {
> myfunc1: function {},
> myfunc2: function{}
> };

That's a syntax error. Should be
...
myfunc1: function () {},
myfunc2: function () {}
...

> in html file i include this script through src
>
> then on body onload i call myvar.myfunc1;
>
> in crome dev console i see error near var, why so ?

You could start by telling us what the error message said.

- stefan

jags

unread,
Aug 30, 2012, 7:01:02 AM8/30/12
to
it is saying "Syntax Error: Unexpected token var"

but why is it a syntax error ? in another example it just works fine !
i picked it from there, just changed names !

jags

unread,
Aug 30, 2012, 8:28:41 AM8/30/12
to
ok, sorry, it was showing error at myFunc1(var dataString)

i changed it to myFunc1(dataString) and it worked :)

thanks
0 new messages