As a related issue, you cannot close over the variable "this" in
javascript, but you can over
other variables. So you see this code for example in the data loader for
DHTML, I bound
__pthis__ to this, and then referenced it as a global in the function
that was subsequently defined, it
will be "closed over" when the function is created.
var __pthis__ = this;
this.req.onreadystatechange = function () {
// [todo hqm 01-20-06] Is 'this' lexically bound to this
lzdataset object in
// this closure? test this with print statements
//Debug.debug('onreadystatechange',
__pthis__.req.readyState, 'status=', __pthis__.req.status);
if (__pthis__.req.readyState == 4) {
// only if "OK"
if (__pthis__.req.status == 200 ||
__pthis__.req.status == 304) {
var elt = null;
var nodes = __pthis__.req.responseXML.childNodes;
//Debug.info('LzDataset.childNodes',
__pthis__.req.responseXML.nodeName, __pthis__.type);
// find first content (type == 1) child node
for (var i = 0; i < nodes.length; i++) {
var child = nodes.item(i);
if (child.nodeType == 1) {
elt = child;
break;
}
}
var d = __pthis__.copyBrowserXML(elt,
ignorewhite, 0);
__pthis__.responseText = __pthis__.req.responseText;
// If this was a proxied request, drill down to
get data
// and discard header info for now.
if (canvas.proxied) {
//Debug.debug('canvas.proxied in data
handler is true');
d = d.childNodes[0].childNodes[0];
}
__pthis__.setData(d);
} else {
__pthis__.onerror.sendEvent(__pthis__.req.status);
}
}}
Sarah Allen wrote:
> I have some code that I just started testing on other machines today,
> and unexpectedly, I started seeing different (broken) behavior on a Mac.
> I've isolated it down to the following test case:
>
> <canvas>
> <node>
> <!--- a reference to the Flash NetConnection object
> @keywords private -->
> <attribute name="_nc" value="null" />
>
> <method name="init">
> super.init();
> this._nc = new NetConnection();
>
> var ok = this._nc.connect('rtmp://localhost/test');
> var t = this;
> this._nc.onStatus = function(info) {
> _root.Debug.write('onStatus ', info.code);
> _root.Debug.write('this (t) ', t); // this is line 17
> }
> </method>
> </node>
> </canvas>
>
> which generates the following:
> WARNING: test.lzx:17: reference to undefined variable 't'
> this (t) undefined
>
> Confused again,
> Sarah
>
> _______________________________________________
> Laszlo-dev mailing list
> [email protected]
> http://www.openlaszlo.org/mailman/listinfo/laszlo-dev
>
>
_______________________________________________
Laszlo-dev mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-dev