/    Sign up×
Community /Pin to ProfileBookmark

IE7- need object in inline javascript?

hmmm my page works with firefox, but in internet explorer i always get an “Error: Object expcted” break…

and the script debugger highlights something like this…

<li onclick=”foo(); Element.hide(‘blarg’);> …

what should i do? do i alwaays have to call an object in IE? (like Foobar.foo()??)

-_-

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@felgallJan 25.2008 — It depends on how foo() is defined.
Copy linkTweet thisAlerts:
@lamdkauthorJan 25.2008 — hmm im kinda of a noob...

foo() is declared alone by itself in a file foo.js

i've never written a class in javascript! do i have to contain it withing something like


var Foo = {

function foo() {

}

}

or something? then i can use Foo.foo()? i think i tried yesterday and i could nt get it to work

?
Copy linkTweet thisAlerts:
@KorJan 26.2008 — Javascript [I]has no classes[/I]. javascript is a prototype language, that means it uses functions and methods applied upon objects. An event handler (as onclick) calls a [B]function[/B], not a variable, which is not quite the same.

A function is to be set as

[B]function [/B][COLOR="Navy"]foo()[/COLOR]{

[COLOR="DimGray"]... code inside ...[/COLOR]

}

The way you have written:

[B]var[/B] [COLOR="DarkGreen"]Foo=[/COLOR]{

...

}

you have set an [B]object[/B]. An object needs pairs [B]property:value[/B]

see also JSON:

www.json.org
Copy linkTweet thisAlerts:
@lamdkauthorJan 26.2008 — hmmmm i see... so does anynone know what i'll have to do to make it work in IE??? (or maybe why it works with firefox and not IE?!)

?
Copy linkTweet thisAlerts:
@lamdkauthorJan 26.2008 — do i have to call the function with "new" ?

(ive been randomely reading)
Copy linkTweet thisAlerts:
@KorJan 27.2008 — In javascript, as in all the OO (Object Oriented) languages, you must first do a OOA (OO Analysis) and later the OOD (OO Design).

In simple words, you must, first, clarify yourself [I]which[/I] is the nature of the problem and [I]what[/I] the system suppose to do (OOA), and only later you can start thinking [I]how[/I] that aim is to be accomplish (OOD) following the specific language's constrains.

Now, what is your OOA? What do you want to do, after all? Create a new property for an object using a function? What kind of object? Why?

In other words, a surgeon learns first [I]why[/I] he has to cut something and later [I]how[/I] to cut something...
×

Success!

Help @lamdk spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...