 |
Just released a new version of the PowerPack
|
 |
|
I've just put the finishing touches to the latest release (v1.1.0.2) of the PowerPack. You can download it right now.
One of the changes made in this release was moving the Javascript objects' methods into closures set through the prototype.
This is interesting stuff, if you're into DHTML, and like watching
paint dry if you don't. Feel free to switch off now.
Javascript's
notion of objects is a bit different from what developers in compiled
OO languages are used to. Instead of having a specific entity
like a constructor, Javascript just uses a function. If the
function returns something, and it's called via a "new" call instead of
a regular function call, then it's assumed to be a constructor.
Which is nice enough, but it does leave you with the problem of how you create methods in your object.
The way it was done int he PowerPack up until now was just to do something like:
function MyObject ()
{
this.myMethod = myMethodBody;
return;
}
function myMethodBody ()
{
return;
}
So
you'd be assigning a reference to the myMethodBody function to the
this.myMethod property on the new object. You could then do
something like:
var myObj = new MyObject ();
myObj.myMethod ();
Which gives you nice OO flavour.
The
new way of doing this in the PowerPack uses closures and
prototypes. This gives the same results as the above mechanism,
but it has a couple of advantages.
The equivalent closure and prototype code for the above would be:
function MyObject ()
{
return;
}
MyObject.prototype.myMethod = function ()
{
return;
}
This again allows you to use code like:
var myObj = new MyObject ();
myObj.myMethod ();
The advantages of this closure and prototype approach are:
- I'm
no longer polluting the global namespace with function names that are
redundant. (Since they'll always be called through their method names,
the function names themselves are never used.)
- The
creation of methods associated with objects can be optimised better,
since it isn't done through the constructor every time an object is
constructed.
- This is a cleaner, more Javascripty approach.
Why
did I wait until now to do this? To be honest, I don't
know. I don't know why they weren't done like this in the first
place. It's not like I wasn't aware of Javascript prototypes -
I've code I wrote in the nineties that used them.
Still, better late than never.
The complete fix list for this release is:
- ComboBox. Layout problem with absolutely-positioned Panels/DIVs in IE.
FIXED.
- ComboBox. Different layout problem with absolutely-positioned Panels/DIVs in Firefox.
FIXED.
- ComboBox. Designer wasn't appearing in design-view.
FIXED.
- ComboBox. Caused Javascript errors in Firefox if Visible was set to False.
FIXED.
- RichTextBox. Toolbar would occasionally become disabled.
FIXED.
- ComboBox, DatePicker, RichTextBox, ShowOnConditionClientSide.
All Javascript files now use enclosures and prototypes for their object definitions,
so they no longer clutter the global namespace.
FIXED.
Categories: PowerPack Permalink #.Posted by 'Geoff' on Sunday, 05 December 2004 at 5:12PM
|
|
 |
 |
 |
|