Extending objects

Every fully typed Element in AwesomeScript has an Extensions attached to it’s type. This array can have Extension objects. Any extension objected added to the array will extend the element type given a specific class and new function provided to extend the object. Below is an example:

TextBox.Extensions.Add(new Extension("required", RequiredTextBox));

function RequiredTextBox(e){
    if(!e || e.Type == Type.String){
        e = new TextBox(e);

    Awesome.Extend(e, RequiredTextBox);
    e.OnBlur.Add(new Delegate(e.Check, e));
    return e;

RequiredTextBox.prototype.Check = function(){
    if(this.Text().length == 0){

For this code to work, once a TextBox has wrapped, if it contains the class "required", the function “RequiredTextBox” is fired, passing in the textbox element so that you may extend yourself. The first bit of code allows it so that you can use the function as a constructor as well to create a RequiredTextBox programmatically.

Last edited Oct 21, 2011 at 8:26 PM by dahrkdaiz, version 4


No comments yet.