JSEclipse 1.5 :: Hidden Treasures :: templates

JSEclipse 1.5 includes a new feature, pretty common in other editors: code templates (also known as code snipets).

JSElispe comes with a set of predefined templates.
JSEclipse templates

I am proposing here to add a new and useful template for the AJAX developers, particularly for the ones that are using prototype.js. The template is for creating and extending a class. The code (straight from prototype.js source code) looks like this:


Form.Observer = Class.create();
Form.Observer.prototype = Object.extend(new Abstract.TimedObserver(), {
  getValue: function() {
    return Form.serialize(this.element);
  }
});

To add a new template just go to Window/Preferences.. and then JSEclipse/Templates. The New… button will open the dialog for adding a new template.

New prototype.js Object.extends() template.

After pasting the code inside the Pattern text area all that remain is to replace parts of the code with template variables: The next image is showing the result.

prototype.js template

Now there is only one thing. Test the template into a JavaScript page:
Insert the prototype.js extends template.

After selecting the template and typing MyClass in the first box this is how the editor looks like:

Editing the inserted template.

It can be noticed one thing: typing MyClass in the first box also changes the value of the first box from the next row. These two boxes were created with ${ClassName} and their values are bound. To move to the next box to be edited just hit Tab.

So, if you are using prototype.js this little template will be quite useful.

Leave a comment

Please be polite and on topic. Your e-mail will never be published.