无法通过as2中的原型向String类添加新函数

发布于 2024-09-13 12:09:45 字数 320 浏览 2 评论 0原文

以下代码;

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

使用 mtasc 编译器会导致此错误:

类型错误字符串没有字段 myFunction

必须可以通过原型向类添加新函数。

我可以做任何配置让 mtasc 能够编译此代码吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悟红尘 2024-09-20 12:09:45

问题是在 myString 变量定义中指定类型信息。

在这种情况下它是可以编译并工作的:

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

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文