Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-27-2006, 02:50 PM   PM User | #1
SavedLinuXgeeK
New to the CF scene

 
Join Date: Aug 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
SavedLinuXgeeK is an unknown quantity at this point
Javascript Inheritance

Hi,

I am dealing with a very unique problem, one that I have eventually come to assume requires the use of eval. I know that eval is highly inefficient, and so I hope to keep it down to about 3 or 4 evals called at the beginning of a page load, and thats it. Essentially I will need to call eval on every inheritance.
The problem stems from the fact that in order to truly acheive 'classical-inheritance', I need to the ability to call parent functions, and the parent's parent functions. Right now I have a slightly dirty method of calling the same function down an entire chain, through all ancestors. But if I call a parent's function, and from within that parent function, it calls another function, I want that function to be called from the scope of the Parent, not the Child. And right now, it calls the function from the scope of the Child.
My idea is to use tokens, like $this, and $parent within the the function definitions, and then replace those tokens with actual references to the Current class and Parent class, ie. Parent.prototype[method].apply(this, arguments); replaces $parent.method(arguments). The only way I can seem to fix this issue is by doing an eval, as I found no acutal way of applying a variable number of arguments to the Function object.
If anyone else has a better idea I am more than happy to listen. Thank you.
SavedLinuXgeeK is offline   Reply With Quote
Old 08-27-2006, 04:15 PM   PM User | #2
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,358
Thanks: 3
Thanked 458 Times in 445 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
eval('FunctionName'+'()');

=

window['FunctionName']();

but better
__________________
Vic

God Loves You and will never love you less.

http://www.vicsjavascripts.org.uk/

If my post has been useful please donate to http://www.operationsmile.org.uk/
vwphillips is offline   Reply With Quote
Old 08-28-2006, 03:39 PM   PM User | #3
Beagle
Senior Coder

 
Join Date: Jul 2005
Location: New York, NY
Posts: 1,084
Thanks: 4
Thanked 19 Times in 19 Posts
Beagle is an unknown quantity at this point
I'm not sure what you're problem here is, if you have an object prototype that defines methods and members, and then you have another object that uses that prototype and adds to it you still have access to the "parent"'s methods and members unless you redfine them. The prototype chain keeps going back as long you want it to.

Perhaps if you could provide some code to explain what you're trying to do, we could help you avoid eval altogether.
Beagle is offline   Reply With Quote
Old 08-28-2006, 04:21 PM   PM User | #4
iota
Registered User

 
Join Date: Oct 2004
Posts: 592
Thanks: 0
Thanked 1 Time in 1 Post
iota is an unknown quantity at this point
There are now JavaScript Prototype Class Framework out there.

You can easily use them to create true OO Javascript.
iota is offline   Reply With Quote
Old 08-28-2006, 05:07 PM   PM User | #5
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
I think you may want to look at Appenix B of my book. Sun has it avaialble on their site here:

http://java.sun.com/javascript/ajaxi...ction_ApB.html

Hope that helps.

Eric
__________________
Tech Author [Ajax In Action, JavaScript: Visual Blueprint]
A1ien51 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:50 AM.


Advertisement
Log in to turn off these ads.