Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Injections / Extensions

#17

Here's an idea for injecting methods into dynamic objects. Create an Injector class that injects a closure into an object's prototype property.

Injects could be defined at the class level:

package currency
{
    public class Money extends Object
    {
        private var _value:Number;
        
        public function Money(value:Number)
        {
            _value = value;
        }
    }
}

public class Currency
{
    Extension.inject(Number, "dollars", function():Money
    {
        return new Money(this);
    });
}

express(Currency);

// if non-strict:
var amount:Money = (5).dollars();

// strict requires a cast to object:
amount = (5 as Object).dollars();

Reported by Dan Schultz · January 21st, 2011 @ 09:33 AM

State: new
Milestone: none
Assigned to: Dan Schultz Dan Schultz

Activity

  1. Dan Schultz
    Dan Schultz
    • Tag set to feature, idea

    January 21st, 2011 @ 09:34 AM

  2. Dan Schultz
    Dan Schultz
    • Milestone set to 0.2.0
    • Milestone order changed from 1 to 0

    January 21st, 2011 @ 09:42 AM

  3. Dan Schultz

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.