How to Tell if myObj.constructor is Enumerable in IE / JScript?

D

dhtmlkitchen

I think this is not possible...


var fnProto = Function().prototype;
var badAss = { constructor : "Chuck Norris" };

result = [
isConstructorEnumerable( fnProto )
,isConstructorEnumerable( badAss )
];


function isConstructorEnumerable( ocean, pacific ) {
var enumerable = false;
// hmmm.
// enumerable = ocean.propertyIsEnumerable( pacific );

return enumerable;
}

expected result: [ false, true ];

Has to work in IE. It seems the only way to tell would be if there's
something else that IE adds to the object constructed in Steps 9-10 of
section 13.2 Creating Function Objects

http://bclary.com/2004/11/07/#a-13.2.2

Unfortunately, IE doesn't properly check the DontEnum flag, so will
return the wrong result for propertyIsEnumerable.
 
R

Richard Cornford

I think this is not possible...


var fnProto = Function().prototype;

You have assigned a reference to the object that is the prototype
property of a new function object returned by - Function() - to the -
fnProto - variable.
var badAss = { constructor : "Chuck Norris" };

result = [
isConstructorEnumerable( fnProto )

Your - isConstructorEnumerable - has two formal parameters, yet you are
only passing one argument to it.
,isConstructorEnumerable( badAss )
];


function isConstructorEnumerable( ocean, pacific ) {
var enumerable = false;
// hmmm.
// enumerable = ocean.propertyIsEnumerable( pacific );

return enumerable;

This function will always return false, as it contains no code that will
change the value assigned to - enumerable.
}

expected result: [ false, true ];

Given the code posted the expected results should be [false, false], but
you did not say what the actual results were.
Has to work in IE.
<snip>

What makes you think it does not 'work' in IE?

Richard.
 

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,997
Messages
2,570,241
Members
46,830
Latest member
HeleneMull

Latest Threads

Top