473,397 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

DOM Prototypes?

Hello all.

Is there any way, in JavaScript, to extend the DOM elements ala the
prototype mechanism?

I would basically like to do is:

DIV.prototype.myfunc = function(){ /* whatever */ }

I know I can add functions to individual elements after they've been
created, but that gets ugly fast for a large document.

TIA,

Dave
Nov 10 '05 #1
3 2664
D. Patterson wrote:
Hello all.

Is there any way, in JavaScript, to extend the DOM elements ala the
prototype mechanism?

I would basically like to do is:

DIV.prototype.myfunc = function(){ /* whatever */ }

I know I can add functions to individual elements after they've been
created, but that gets ugly fast for a large document.


I think that exact same question was asked (and discussed at length)
in the thread 'Instantiate extended browser objects':

<URL:http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/26e7167f7b5542bd/b5bf1f5cf9f6b69a?tvc=1&q=Instantiate+extended+brow ser+objects#b5bf1f5cf9f6b69a>

--
Rob
Nov 10 '05 #2
Thanks for the link.
The answer is as I feared. Basically, no-go.

"RobG" <rg***@iinet.net.auau> wrote in message
news:43***********************@per-qv1-newsreader-01.iinet.net.au...
D. Patterson wrote:
Hello all.

Is there any way, in JavaScript, to extend the DOM elements ala the
prototype mechanism?

I would basically like to do is:

DIV.prototype.myfunc = function(){ /* whatever */ }

I know I can add functions to individual elements after they've been
created, but that gets ugly fast for a large document.
I think that exact same question was asked (and discussed at length)
in the thread 'Instantiate extended browser objects':

<URL:http://groups.google.com/group/comp....e_frm/thread/2
6e7167f7b5542bd/b5bf1f5cf9f6b69a?tvc=1&q=Instantiate+extended+brow ser+object
s#b5bf1f5cf9f6b69a>
--
Rob

Nov 10 '05 #3
VK
D. Patterson wrote:
Thanks for the link.
The answer is as I feared. Basically, no-go. "RobG" wrote
I think that exact same question was asked (and discussed at length)
in the thread 'Instantiate extended browser objects':

<URL:http://groups.google.com/group/comp....e_frm/thread/2
6e7167f7b5542bd/b5bf1f5cf9f6b69a?tvc=1&q=Instantiate+extended+brow ser+object
s#b5bf1f5cf9f6b69a>


In addition to both discussion I would like to add that IE exposes
generic <element> object for behavior scripting:
....
DIV { behavior:url(SingAndDance.htc) }
....
would make each new div by default move across the screen and play
country music (if you write the corresponding htc script properly).

More universally you should use the standard way by declaring custom
new space (say "X") and having there your <X:DIV> element with all
needed properties.

I have to admit though that in both discussions I missed to catch up on
the ground reasonning: why sex change operations on DIV itself is
anyhow better then:
....
var myDiv = new extendedDIV();
myDIV.addTo(document.body);
....

???

Nov 10 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

145
by: David MacQuigg | last post by:
Playing with Prothon today, I am fascinated by the idea of eliminating classes in Python. I'm trying to figure out what fundamental benefit there is to having classes. Is all this complexity...
7
by: Michele Simionato | last post by:
So far, I have not installed Prothon, nor I have experience with Io, Self or other prototype-based languages. Still, from the discussion on the mailing list, I have got the strong impression that...
14
by: fb | last post by:
Does the C language require you to prototype functions? If it's not required, is it recommended?
9
by: Grumble | last post by:
Hello everyone, I've come across some strange code. Here it is, stripped down: int main(void) { int *foo; int *bar(); foo = bar(0); return 0;
13
by: DevarajA | last post by:
If a function is visible everywhere, even out the file where it is declared and defined, why should i write prototypes? -- Devaraja (Xdevaraja87^gmail^c0mX) Linux Registerd User #338167...
7
by: junky_fellow | last post by:
Can a function have two different prototypes ? If not , then how can main() have two different prototypes ? int main(void) and int main argc(int argc, char *argv) I mean to say, if I declare...
1
by: petermichaux | last post by:
Hi, I have searched the archives but didn't find the questions and answers I am looking for. I have been looking at Prototype.js quite a bit lately as I need to create a very small library of...
20
by: Ari Krupnik | last post by:
scripts can add methods to the prototypes of builtin objects in JaavScript. I can assign functions to String.prototype.*, for instance. I want to add a method to Node, but when I try to execute...
73
by: Steph Barklay | last post by:
Hi, I'm currently taking a data structures course in C, and my teacher said that function prototypes are not allowed in any of our code. He also said that no professional programmers use function...
4
by: robtyketto | last post by:
Greetings, I’m writing a research report on justifying disposable prototypes. The problem being there is a wealth of material regarding failures in the IT press and some of these put partial...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.