MSIE 6.0 does not support protyping with objects created with document.createElement.

R

raoul

MSIE 6.0 apparently does not support protyping with objects created
with document.createElement, while Firefox does.

I tested it by typing it into the adress bar, but it also appears to be
the case for code embedded in a HTML document. Here's a simple segment
of code to demonstrate the difference:

javascript: function myObj(){};myObj.prototype =
document.createElement('a'); var x = document.createElement('a'); var
y=new myObj(); var z= new Object(); alert(x.href) /*blank in both FF &
MSIE6 */; alert(y.href) /* blank in FF but 'undefined' in MSIE6 */;
alert(z.href) /* 'undefined' in both FF & MSIE6 */;

I wonder why that is (apart from the fact that MSIE implements JScript
and not javascript), and can anyone tell me which of both browsers is
complient with W3C standards?

regards,
Raoul
 
P

Patient Guy

raoul said:
MSIE 6.0 apparently does not support protyping with objects created
with document.createElement, while Firefox does.

I tested it by typing it into the adress bar, but it also appears to be
the case for code embedded in a HTML document. Here's a simple segment
of code to demonstrate the difference:

javascript: function myObj(){};myObj.prototype =
document.createElement('a'); var x = document.createElement('a'); var
y=new myObj(); var z= new Object(); alert(x.href) /*blank in both FF &
MSIE6 */; alert(y.href) /* blank in FF but 'undefined' in MSIE6 */;
alert(z.href) /* 'undefined' in both FF & MSIE6 */;

I wonder why that is (apart from the fact that MSIE implements JScript
and not javascript), and can anyone tell me which of both browsers is
complient with W3C standards?

W3 Consortium does not have a "recommendation" (or standard, if you will)
on ECMAscript/Javascript/Jscript.

Possibly useful reading material:

http://loadaveragezero.com/app/drx/Programming/Languages/JavaScript
http://en.wikipedia.org/wiki/ECMAScript
http://www.piclist.com/techref/inet/iis/jscript/htm/js551.htm
 
R

raoul

Patient said:
W3 Consortium does not have a "recommendation" (or standard, if you will)
on ECMAscript/Javascript/Jscript.

Possibly useful reading material:

http://loadaveragezero.com/app/drx/Programming/Languages/JavaScript
http://en.wikipedia.org/wiki/ECMAScript
http://www.piclist.com/techref/inet/iis/jscript/htm/js551.htm

Thanks, but the question is rather about DOM and ECMAScript binding.
And according to this site, http://www.w3.org/DOM/, W3C does in fact
define normative binding for ECMAscript and the DOM, and it seems to be
summarized here
http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/ecma-script-language-binding.html.
However I'm not an expert in such specifications. Rather a newbie, not
realy interested in these specifications, who is trying to make sense
of, and learning what to expect from such a specification. I just would
like know what the W3C "recommendations" say about this point. I was
therefore hoping someone here would be able to explain me a bit more.

regards,
raoul
 
M

Michael Winter

raoul said:
[snip]
W3 Consortium does not have a "recommendation" (or standard, if you
will) on ECMAscript/Javascript/Jscript.
[snip]

Thanks, but the question is rather about DOM and ECMAScript binding.

One was, but the reason for your original post was not.

Prototypical inheritance is a /language/ feature so behaviour in this
regard is defined by the ECMAScript specification (ECMA-262). As
previously stated, the W3C are not responsible for determining this
behaviour.
And according to this site, http://www.w3.org/DOM/, W3C does in fact
define normative binding for ECMAscript and the DOM ...

Indeed, but that's not really relevant. However, to answer your second
question, Firefox has fewer inconsistencies in relation to the DOM.
Microsoft omit some features (though in some cases, they may be
available through another interface), and implement others differently
than how the W3C defines them.

[snip]
I just would like know what the W3C "recommendations" say about this
point.

Nothing, as I hope would be clear, now. As for what the ECMAScript
specification states:

Whether or not a native object can have a host object as its
[[Prototype]] depends on the implementation.
-- 8.6.2 Internal Properties and Methods, ECMA-262 3rd Ed.

So, both behaviours are correct as it's up to a particular
implementation to decide whether host objects, such as DOM nodes, can
act as prototypes.

[snip]

Mike


Please trim quoted text when replying to only the relevant material.
 
G

goulart

myObj.prototype =
document.createElement('a');

???

You're setting myObj.prototype to be relevant only to the A element you
created there. Since it's a specific element, myObj wont show up in
other properties for other elements.
 
M

Michael Winter

myObj.prototype =
document.createElement('a');

???

You're setting myObj.prototype to be relevant only to the A element
you created there.

I'm not entirely sure what you mean by that, ...
Since it's a specific element, myObj wont show up in other properties
for other elements.

.... but you have that backwards: the properties of the anchor element
are meant to be readable as properties of objects created by the myObj
constructor function[1].

In any case, the idea is likely a non-starter. The objects created from
said constructor won't actually behave like links. Assigning to the href
property, for instance, wouldn't change the property value for the
element as properties inherited from the prototype chain are only used
during reading. Upon assignment, a new property is created on the
constructed object itself. Moreover, all objects created from the myObj
constructor function will share the same anchor element, which is surely
not intended.

An alternate approach is to use augmentation:

function MyObject(base) {
base.newProperty = 'value';

return base;
}

The base argument can be any object (in this case, an anchor element),
but it /must/ be an object[2] of some sort.

Mike


Please quote relevant material when replying, and actually reply to the
right post. goulart, your message had nothing to do with what I wrote,
and should have been addressed to the OP.


[1] Note to OP: It's generally considered a good idea to give
constructor function names a capitalised initial to
distinguish them from regular functions.
[2] Values do not have properties. Trying to access a property,
either for reading or writing results in the creation of a
temporary object that is discarded before the statement
ends.
 
J

Jim Ley

I wonder why that is (apart from the fact that MSIE implements JScript
and not javascript), and can anyone tell me which of both browsers is
complient with W3C standards?

It's nothing to do with a JScript / javascript distinction - the W3
DOM objects are host objects, so there is no requirement to expose
prototype's, it is neither required or forbidden, so both behaviour is
completely in accordance with both W3C specifications and ECMA 262 in
this respect.

Jim.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top