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

2007-09-10:

[13:57] <rjb> hmm, i'm trying to figure out whether it's possible to conditionally define a constant in javascript, but no luck yet
[13:59] <rjb> i mean, like const foo = 'BAR'; but first checking whether it doesn't already exist, to avoid throwing an error on redefining a constant
[14:04] <rjb> (no, using try/catch doesn't work)
[14:28] <rjb> wrapping it in a function is nogo, too
[14:35] <zumbrunn> rjb, are you looking for global.foo = 'BAR'; ?
[14:37] <zumbrunn> also, depending on where/when you set it, you might need to use defineLibraryScope('foo') to make it survive across requests
[14:39] <rjb> no not really
[14:39] <rjb> that's a variable, i'd like a true constant
[14:40] <rjb> and my question is general of ecmascript, not helma-specific
[14:50] <rjb> ok, i think i got it
[14:51] <rjb> it seems it can't be done with a 'const' declaration
[14:51] <rjb> but a read-only property is nearly as good
[14:51] <rjb> so:
[14:51] <rjb> __defineGetter__('html', function(){return <html/>;});
[14:55] <rjb> and:
[14:55] <rjb> if(typeof(html)=='undefined')__defineGetter__('html', function(){return <html/>;});
[14:55] <rjb> cool
[14:57] <rjb> (it appears 'const' declarations are processed at compile time, and if you issue one twice in the same context, compilation will fail)
[14:58] <rjb> (same context and scope, actually)
[15:01] <rjb> well actually it's not quite as good: reassigning to a constant throws an error, to a readonly property fails silently
[15:10] <rjb> if(typeof(html)=='undefined')
[15:10] <rjb> {__defineGetter__('html', function(){return <html/>;});
[15:11] <rjb> __defineSetter__('html', function(whatever){throw new Error("don't touch this");})}
[15:11] <rjb> there :-)
[15:13] <zumbrunn> brute force ;-)
[15:13] <rjb> gotta love the flexibility of javascript ;-)
[15:13] <zumbrunn> yep
[15:32] <rjb> http://helma.pastebin.com/d3c23751d
[23:10] <peter_12> of all the Java servers what makes Jetty the right fit for Helma?

 

 

In the channel now:

Logs by date: