/    Sign up×
Community /Pin to ProfileBookmark

Javascript syntax confusion

Hi all

I’m new to javascript but come using Actionscript for a number of years and I’m really confused by some of the Js syntax.

I’m trying to work with mootools Fx.Slide

[CODE]
window.addEvent(‘domready’, function() {
var status = {
‘true’: ‘open’,
‘false’: ‘close’
};

var myVerticalSlide = new Fx.Slide(‘vertical_slide’);

$(‘slidein’).addEvent(‘click’, function(e){
e.stop();
myVerticalSlide.slideIn();
});

$(‘slideout’).addEvent(‘click’, function(e){
e.stop();
myVerticalSlide.slideOut();
});

myVerticalSlide.addEvent(‘complete’, function() {
$(‘vertical_status’).set(‘html’, status[myVerticalSlide.open]);
});
});
[/CODE]

I’m confused with the use of parentheses ‘()’, In the window.addEvent function the end parentheses looks like it finishes outside the function.

[CODE]
window.addEvent(‘domready’, function() {

});
[/CODE]

I would of expected it to look like

[CODE]
window.addEvent(‘domready’, function()) {

};
[/CODE]

Also could someone explain the use of $ in

[CODE]
$(‘slidein’)
[/CODE]

Can someone explain whats going on here or point me in the direction of a tutorial that might – I have looked but can’t find anything.

Any help would be greatly appreciated.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@scragarFeb 19.2009 — window.addEvent('domready', [B]function() {

}[/B]);

The whole function is passed as an argument, [B]function()[/B] on it's own would throw an error, since there is no body to the function.

The $ is a function, you can define it like any other function, most javascript libraries tend to use it for returning a custom object. The argument is normally used in the function [b]document.getElementById[/b] to grab the element you want to use for the functions the custom object makes available.
×

Success!

Help @ttmt 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...