In my spare time I have been playing around with javascript a lot. I'm trying to sharpen my javascript skills by writing a web application that looks like a desktop application using pure javascript and keep away from HTML as much as possible. I have done this using ExtJS.ExtJS is a javascript framework and GUI toolkit that encapsulates common widgets and functionality into classes and uses javascript object orientation capabilities extensively. A typical ExtJS class looks like this:
This code snippet is creating a new MemoryProxy constructor, as a member of the Ext.data object, i.e., it's package. Then it uses Ext's Ext.extend to make some magic and create a protype inheritance from Ext.data.DataProxy. The thrid parameter to Ext.extend is an object literal expression that will become part of Ext.data.MemoryProxy's prototype, the functions present in this object will override the functions that were already present in Ext.data.DataProxy.So what's the problem with this code you may ask.... Absolutely nothing. This is pretty much standard OO Javascript. Many frameworks are already using this pattern and it has been working great.Now I do have a problem with code... it's not very intuitive to a Java developer. I know, I know... who cares about them, Java developers should be developing JAVA right? Well that's a valid point. But still, I consider myself a Java developer so I do care about us :D. So my idea is to create a small library that would add some syntactic sugar to javascript to make it a bit more like Java. Still with me? Like the idea?To be continued (on my next post...)
- Ext.data.MemoryProxy = function(data){
- Ext.data.MemoryProxy.superclass.constructor.call(this);
- this.data = data;
- };
- Ext.extend(Ext.data.MemoryProxy, Ext.data.DataProxy, {
- load : function(params, reader, callback, scope, arg){
- params = params || {};
- var result;
- try {
- result = reader.readRecords(this.data);
- } catch(e) {
- this.fireEvent("loadexception", this, arg, null, e);
- callback.call(scope, null, arg, false);
- return;
- }
- callback.call(scope, result, arg, true);
- },
- update : function(params, records){
- }
- });
This code snippet is creating a new MemoryProxy constructor, as a member of the Ext.data object, i.e., it's package. Then it uses Ext's Ext.extend to make some magic and create a protype inheritance from Ext.data.DataProxy. The thrid parameter to Ext.extend is an object literal expression that will become part of Ext.data.MemoryProxy's prototype, the functions present in this object will override the functions that were already present in Ext.data.DataProxy.So what's the problem with this code you may ask.... Absolutely nothing. This is pretty much standard OO Javascript. Many frameworks are already using this pattern and it has been working great.Now I do have a problem with code... it's not very intuitive to a Java developer. I know, I know... who cares about them, Java developers should be developing JAVA right? Well that's a valid point. But still, I consider myself a Java developer so I do care about us :D. So my idea is to create a small library that would add some syntactic sugar to javascript to make it a bit more like Java. Still with me? Like the idea?To be continued (on my next post...)
0 comments:
Post a Comment