How to implement such a class?

S

sleepinglord

We know objects returned from DOM's createElement() method have these
features:
1. They can be added and showed by appendChild method in various of
ways.
2. They can be searched by getElementByXXX and some other method.
3. Some other common method in Node, Element classes.

I'd like to write a class. It can be compatible with DOM's Elements,
that is, can be operated by appendChild, getElementByXXX, etc. How to?
 
P

petermichaux

sleepinglord said:
I'd like to write a class. It can be compatible with DOM's Elements,
that is, can be operated by appendChild, getElementByXXX, etc.

I'm curious why?
 
S

sleepinglord

Why not?

Suppose you write a new GUI controlor.
The most naturally way to operate it is to operate it as a normal DOM
element, isn't it?
 
L

Lasse Reichstein Nielsen

sleepinglord said:
I'd like to write a class. It can be compatible with DOM's Elements,
that is, can be operated by appendChild, getElementByXXX, etc. How to?

You probably can't.

DOM elements are host objects, i.e., they are provided by the runtime
environment that the Javascript script is running in. They are not bound
by the rules that the objects created by the programmer is.

Objects you create yourself, native objects, will probably not be able
to contain the internal plumbing that allows DOM elements to work as
they do.

If you try to inheirt from a DOM element object (there are no classes
in Javascript, inheritance happens diretly between objects), then it
will loose access to some of the special features of the host object.
Reading might still work, but updating a property will only change it
on the nativ object you created, and not carry through to the DOM
elment below.

/L
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top