Extending a Data Type

MonkeyC supports applying instance methods to a built in type. Such as:

var num1, num2;
num2 = num1.toFloat();


I'd like to create my own instance method that can be used against built in types. For example:

num2 = num1.myOwnMethod();


I can't seem to get this to work. I assume I'd need to create a module that has classes that extend Float, Integer, etc. Except it seems maybe those parent classes aren't exposed to allow it. Or is there another way to make this work?

Thanks!
  • Former Member
    Former Member
    It isn't possible to directly extend the basic built in types (things that fit in 32 bits). You would need to create a complete wrapper for the type, and would lose the speed benefits these types have.

    It would be better to create a processing object or global function that does this operation.

    num2 = numberHelper.myOwnMethod(num1);
    or
    num2 = $.myOwnMethod(num1);