Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: [ ODDITY ] TypeError: Error #1006 push is not a function  (Read 11811 times)
meekgeek
Full Member
***
Posts: 25


View Profile Email
« on: November 08, 2007, 06:18:20 »

Ok, I'm not sure if I'm missing something.

Apparently, if I registerCommand with the string "join" for the first parameter.  I get that error at the top.

As soon as I change it to something else like, "register" it works.

The error leads me to the registerObserver method in the org.puremvc.core.view::View Class.

Is this a reserved word or something?
« Last Edit: November 10, 2007, 07:59:19 by puremvc » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: November 08, 2007, 08:08:17 »

Wow, that is beyond strange.

It all comes down to this evaluation in the View.registerObserver method:

:

if( observerMap[ notificationName ] != null ) {
observerMap[ notificationName ].push( observer );
} else {
observerMap[ notificationName ] = [ observer ];
}

The if statement simply evaluates improperly if that notificationName is the String value 'join'. And it is case sensitive. For instance 'Join' does not cause the problem. Specifically, it acts as though this were true:

:

observerMap[ 'join' ] != null

But it is not. It is as if the string join is being used internally in the actionscript engine. I tried to flush out the problem with the following but could not duplicate the issue.

:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="testHash()"
>
<mx:Script>
<![CDATA[

[Bindable]public var myHash:Array = new Array();
public static const EVILKEY:String = "join";
public static const GOODKEY:String = "kittensAndRadishes";

public function testHash():void
{
myHash[ GOODKEY ] = ["Testing", "a", "good", "key"];
lstGoodKey.dataProvider = myHash[ GOODKEY ];
myHash[ GOODKEY ].push( "OK" );

myHash[ EVILKEY ] = ["Testing", "the", "evil", "key"];
lstEvilKey.dataProvider = myHash[ EVILKEY ];
myHash[ EVILKEY ].push( "OK" );

}

]]>
</mx:Script>
<mx:List id="lstGoodKey"/>
<mx:List id="lstEvilKey"/>
</mx:Application>

Clearly something a little strange is going on. I will do more research to try and figure out how to duplicate the problem outside PureMVC.

For now, just be admonished that 'join' as the key of an associative array appears magical (though not officially reserved in this context) and avoid using it as the constant value in a notification name.


Hardly difficult to work around, but very wierd nonetheless.
Logged
meekgeek
Full Member
***
Posts: 25


View Profile Email
« Reply #2 on: November 09, 2007, 10:43:04 »

Nice to know I wasn't going crazy  :)
Logged
Pages: [1]
Print