Oct 09

At the end of the day, AJAX classes are functions

Posted in MS AJAX      Comments Off on At the end of the day, AJAX classes are functions

While I was hanging around the AJAX forums, I found this interesting thread. The problem was a stack overflow, but the interesting thing was what was causing that error in the first place.

here”s the scenario: a top page has a method that receives an object. It also has an iframe which loads another page. Both pages load the same custom js file that defines an AJAX class (ie, a class defined by using the ASP.NET AJAX OO helpers). The method of the main page did only one thing: it called the IsInstanceOfType method, passing it the parameter the method received. The inner page had one button that would call the main page method and would pass an instance  of the custom class defined on the custom js file (take a look at the thread to see the code).

Even though some might expect that the line

var typeResult1 = JasonSoft.JWindow.isInstanceOfType(arg1); 

will be true, it won”t. Internally, that method will end up comparing the constructor of the type (represented by a function object)  with the constructor associated with the object arg1 (which is also a function). If you recall that arg1 was passed from a different window, then you might see that, even though conceptually the object is of the “same” type, the truth is that it”s not. Why? simple: the types were defined in different windows, which means that we”re talking about 2 different methods (just think about .NET and identity vs equality check between objects). So, the key here is understanding that if you define the same AJAX type on different windows,then you”re talking about different types.