[Javascript] (no subject)
Håkan Magnusson
hakan at backbase.com
Fri Apr 16 04:45:48 CDT 2004
1. I'm not 100% sure on what you mean, but yes, the loMainItem can be
referenced/accessed by all functions (in the same execution scope) if
you define it globally. Like so:
var loMainItem;
loMainItem = 'Hello World'
function Item0100( param1, param2, param3 ) {
alert(loMainItem);
}
Item0100(1,2,3); // Will alert 'Hello World'
JavaScript do support prototyping and inheritance, meaning you can
create the loMainItem and let Itom0100 inherit from that object. This
has to be done in a slight different way than what you might be used to.
Have a look at this page:
http://www.crockford.com/javascript/inheritance.html
2. There is no built in reference to an objects "parent"/owner, but you
can quite easily build that kind of relation while constructing your
data set. I think the above link will throw you a good way in the right
direction.
Regards,
H
Mike Dougherty wrote:
> Question 1 of 2:
>
> I'm developing a stateful interface (with Javascript and DHTML) to
> customize an object. Suppose I have the following:
>
> loMainItem.Item0200[1].Item0250[1].Item0100[1] = new Item0100(
> *paramlist* )
>
> where:
> function Item0100( param1,param2,param3 ) {
> if (param1 == 0) {
> this.prop1 = loMainItem.prop1 /* inherit from loMainItem */
> *** more code removed for brevity ***
> } /* if(param1 == 0) */
> else {
> this.prop1 = param1 /* value from parameter */
> *** more code removed for brevity***
> } /* ELSE: if(param1 == 0) */
> } /* Item0100(..) */
>
>
> Can the loMainItem object be referenced if it is defined in a global
> scope? (it does not appear to work) This would be a lazy solution to a
> server-side data aquisition problem that would probably be better served
> 'the right way' - so I'm mostly interested in an explaination of any
> scoping issues around the object constructor function.
>
> Question 2:
> Given the object(s) above, can I implicitly reference an object's
> parent with "this.parent"? Most of the online help i've seen refers to
> the parent of built-in objects, so I don't know how to use it on custom
> objects.
> ex:
> loCurrentItem0100 = loMainItem.Item0200[1].Item0250[1].Item0100[1]
> alert( "Parent object: " + loCurrentItem0100.parent.Item0250Id )
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
>
More information about the Javascript
mailing list