Question

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?

Was it helpful?

Solution

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top