can't add a new function to String class via prototype in as2

492 views Asked by At

following code;

String.prototype.myFunction = function() { trace("my function is called"); };
var myString:String = "myString";
myString.myFunction();

causes this error with mtasc compiler:

type error String has no field myFunction

it must be possible to add new functions to a class via prototype.

is there any configuration i can do for mtasc to be able to compile this code?

1

There are 1 answers

0
ekesken On BEST ANSWER

problem was specifying type information at myString variable definition.

it is compilable and working in that case:

String.prototype.myFunction = function() { trace("my function is called"); };
var myString = "myString";
myString.myFunction();