Hopbot log for 2007-07-29 - Helma IRC channel: #helma on irc.freenode.net

2007-07-29:

[6:56] <jsp> repeat in the hopes someone will know: is there a way to read in the script environment the accessname property of a collection? specifically what I'm trying to do is write a generic HopObject method that will return the names of all its children. Sometimes the name is 'name', but sometimes it's 'title' or something else. If a hopObject could learn its own _children.accessname property, it'd be as simple as
[6:56] <jsp> a = [];
[6:56] <jsp> this.forEach(function(c){ a.push(c[this._children.accessname]
[6:57] <jsp> oops
[6:57] <jsp> this.forEach(function(c){ a.push(c[this._children.accessname]
[6:57] <jsp> dangit
[6:58] <jsp> Here we go:
[6:58] <jsp> a = []; aname = this._children.accessname;
[6:58] <jsp> this.forEach(function(c){ a.push(c[aname]); });
[6:58] <jsp> return a;
[6:59] <jsp> (i'm going to sleep, though)
[14:55] <zumbrunn> jsp, wake up! ;-)
[14:56] <zumbrunn> ...so that I can tell you that I do not know the answer...
[14:56] <zumbrunn> I don't think there is a straight forward way to get the accessname
[14:56] <zumbrunn> the only way I know of is like this:
[14:57] <zumbrunn> app.getPrototype('HopObject').getTypeProperties().getProperty("_children.accessname")
[14:58] <zumbrunn> which also means you need to walk up the prototype chain and check in each prototype individually
[15:12] <jsp> hm
[15:14] <jsp> how can I tell what my type name is (e.g., HopObject or MyObject or whatever)?
[15:16] <jsp> (I don't mind if it's convoluted so long as I can find a way to do it generically)
[15:17] <jsp> (switching computers... I'll be back as midnightmonster)
[16:14] <zumbrunn> midnightmonster, again I do not know a clean solution, but I just had to do this myself a few days ago...
[16:15] <zumbrunn> looking for my ugly workaround...
[16:16] <zumbrunn> hmm, we need a pastebin somewhere...
[16:17] <jsp> new project! a helma pastebin!
[16:18] <zumbrunn> yep :-)
[16:18] <zumbrunn> http://helma.zumbrunn.net/downloads/snippetbucket/prototypeChain.js
[16:19] <zumbrunn> this was intended as a workaround until I find the right way of doing this
[16:19] <zumbrunn> but I haven't so far
[16:24] <midnightmonster> the string parsing is pretty ugly
[16:24] <midnightmonster> but seems like it should be stable
[16:26] <midnightmonster> ..asnames can be replaced with this.getPrototypChain().map(function(v){ return v.toString().split(' ')[1].slice(0,-1); });
[17:21] <midnightmonster> I'm just playing in firebug here, but myObj.__proto__.toString() is always [object Object]
[17:22] <midnightmonster> never something useful like [object NameOfTheDaggumThing]
[17:25] <zumbrunn> well, it's working in Helma
[17:25] <zumbrunn> :-)
[17:28] <midnightmonster> which is a good thing, but it seems like there should be some way to get this
[17:28] <midnightmonster> generically in javascript
[17:29] <zumbrunn> I agree, there must be something simple I'm missing right now
[17:29] <zumbrunn> seems like such a basic thing
[17:57] <jsp> dang. Helma does some magic.
[17:57] <jsp> with HopObjects
[17:57] <jsp> to get this stuff right-ish
[17:59] <jsp> myObject.__proto__ returns something useful in Helma as does myObject.constructor if myObject extends HopObject
[17:59] <jsp> but with plain objects, those are both useless:
[17:59] <jsp> function a(){ this.aprop = 'a'; }
[17:59] <jsp> function b(){ this.bprop = 'b'; }
[17:59] <jsp> b.prototype = new a;
[17:59] <jsp> function c(){ this.cprop = 'c'; }
[17:59] <jsp> c.prototype = new b;
[17:59] <jsp> tmp = new c();
[17:59] <jsp> tmp.constructor;
[17:59] <jsp> tmp.constructor==a()
[18:00] <jsp> tmp.__proto__.toString = [object Object]
[18:00] <jsp> ==
[18:00] <zumbrunn> HopObjects are special
[18:01] <zumbrunn> they are definitely not plain Javascript objects
[18:01] <jsp> whatever that magic is is presumably why writing my own constructor for one of my hopobjects didn't work
[18:01] <zumbrunn> they are just made to behave like Javascript objects as much as possible
[18:02] <zumbrunn> http://dev.helma.org/wiki/Mocha+Inheritance/
[18:03] <jsp> really irritating that there doesn't seem to learn the names of everything in an object's prototype chain in plain javascript, though
[18:03] <jsp> you can test them all
[18:03] <zumbrunn> yes
[18:03] <jsp> tmp instanceof b == tmp instanceof c == true
[18:05] <zumbrunn> the bad news is javascript is broken, the good news is you can fix it with more javascript :-)
[18:05] <jsp> word
[18:06] <jsp> thanks.. gone for now.

 

 

In the channel now:

Logs by date: