o.__proto__ == c.prototype
is usually equivalent to:
o instanceof c
except in the case where you are trying to see if o is a _direct_
instance of c. But that does not seem to be the case here.
I cannot find a way in ECMA to ask if something is a direct instance
of a class. both instanceof and isPrototypeOf test for direct and
indirect inheritance.
On 2006-04-18, at 11:27 EDT, Henry Minsky wrote:
> This code in LzDataElement tries to classify an object arg, o, by
> looking at
> it's __proto__ field.
> Do we have protocol for finding object's class type that doesn't
> rely on
> __proto__ (which won't work
> in IE 6 javascript, I believe)
>
>
>
> LzDataElement.__LZv2E = function ( o ) {
>
> var type = typeof( o );
> type.toLowerCase();
>
> var c = [];
> if (type == "object") {
> var proto = o.__proto__;
> if ( proto == LzDataElement.prototype ||
> proto == LzDataNode.prototype ) {
> c[0] = o;
> } else if (proto == Date.prototype) {
>
> type = "date";
> // FIXME: [2004-04-10 pkang] what should we do with dates?
>
> } else if (proto == Array.prototype) {
> type = "array";
> var tag = (o.__LZtag != null ? o.__LZtag : 'item');
> for (var i=0; i < o.length; i++) {
> var tmpC = this.__LZv2E( o[i] );
> c[i] = new LzDataElement(tag, null, tmpC );
> }
> } else {
> type = "struct";
> var i = 0;
> for (var k in o) {
> // skip any properties that start with __LZ
> if (k.indexOf('__LZ') == 0) continue;
> c[i++] = new LzDataElement(k, null, this.__LZv2E(o
> [k]));
> }
> }
> } else if (o != null) {
> c[0] = new LzDataText( o );
> }
>
> if (c.length == 0) c = null;
>
> return c;
> }
>
> --
> Henry Minsky
> Software Architect
> [EMAIL PROTECTED]
_______________________________________________
Laszlo-dev mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-dev