New Syntax for Old Guy

A

andresjv

It's me again, please tell me if the following sentences are true for
the next code:

<form onsubmit="return AIM.submit(this, {'onStart' : startCallback,
'onComplete' : completeCallback})"

a) when the form submits, it calls method submit of object AIM
b) I don't need to create an instance like var a = new AIM() but I can
if I want. The guy who wrote this code didn't do it, because it would
have something like this:
onsumbit="var a = new AIM; return a.submit(this, {'onStart' :
startCallback, 'onComplete' : completeCallback})"
c) second parameter is an anonymous instance with two attributes:
onStart and onComplete. Each of these functions point to callback
functions.
d) Why do onStart and onComplete are surrounded by single quotes? is
it necessary? I have seen other examples with no quotes, but I might
be confusing ideas: AIM = { frame : function(c) { } }

Thank you
 
T

Thomas 'PointedEars' Lahn

It's me again, please tell me if the following sentences are true for
the next code:

<form onsubmit="return AIM.submit(this, {'onStart' : startCallback,
'onComplete' : completeCallback})"

a) when the form submits, it calls method submit of object AIM

*Before* it is submitted, i.e. when the `submit' event of the `form' element
occurs, the attribute value is passed from the UA to the script engine,
which then executes the code (and calls the method eventually). The return
value of the method is then returned to the calling event handler: if it is
`false', the form is not submitted.
b) I don't need to create an instance like var a = new AIM() but I can
if I want. The guy who wrote this code didn't do it, because it would
have something like this:
onsumbit="var a = new AIM; return a.submit(this, {'onStart' :
startCallback, 'onComplete' : completeCallback})"

Wrong.

As there are no classes, there are no instances; there are only objects.

`AIM' is a reference to an (Object) object, not to a constructor (a Function
object); it cannot be used with the `new' keyword. You should have tried first.
c) second parameter is an anonymous instance with two attributes:
onStart and onComplete. Each of these functions point to callback
functions.

Wrong. It is a reference to an Object object, written as an Object literal.
That object is initialized with two properties. The values of these
properties are variable values or references to other objects, who knows.
If the property values are references to Function objects (or at least
[[Call]]able objects), then it is reasonable to assume that their nam
tells of their purpose.
d) Why do onStart and onComplete are surrounded by single quotes? is
it necessary?

Not here, because the property names are also identifiers.
I have seen other examples with no quotes, but I might
be confusing ideas: AIM = { frame : function(c) { } }

Same idea, different style.

Please read at least the JavaScript 1.5 Guide (linked in the FAQ) before
you ask further such questions.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top