QML - 将JS函数的代码作为字符串获取 [英] QML - getting the code of a JS function as a string

查看:820
本文介绍了QML - 将JS函数的代码作为字符串获取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来可以在JavaScript中获得函数的代码,并且它很简单:

  function foo(){...} 
foo.toString()

然而,在QML中这样做给了我一个相当平淡的函数(){[code]}

那么有没有办法获得 [code] 部分呢?我也试过 JSON.stringify()但它没有任何好处。 div>

我想总结一下在评论中发生的讨论,因为这可能是对未来搜索的一个很好的回应。



如前所述在评论中,它看起来是QML的一个明显缺陷。
这里他们声称:


QML运行时实现ECMAScript语言规范标准

无论如何,它实际上并没有。



感谢Meetfe,这里是关于该问题的开放漏洞的链接。



同样的错误似乎是 here ,他们在这里建议查看参考资料以获取更多详细信息: p>


有关详细说明,请参阅ECMA-262规范。 $ b

它至少(至少在我看来)是一个完全兼容的声明,它再一次让我思考一个bug,而不是部分实现规范。



因此,不幸的是,这是将一个函数进行字符串化的有意义的方式(它确实是有意义的,因为它是一个兼容Ecmascript的环境),但是它在QML中不能正确工作,即使它应该如文档中所述。 p>

It seems like it is possible to get the code of a function in JavaScript, and that it is as simple as:

function foo() {...}
foo.toString()

However, doing that in QML gives me a rather uninspiring function () { [code] }

So is there a way to get the [code] part as well? I also tried JSON.stringify() but it didn't do any good.

解决方案

I'd like to sum up the discussion that took place in the comments, for this can be a good response for future searches.

As already stated in the comments, it looks to be a noticeable bug of QML. Here they claim that:

the QML runtime implements the ECMAScript Language Specification standard

Anyway, it actually doesn't.

Thanks to Meetfe, here is the link to the open bug regarding the issue.

The same error seems to be here, where they suggest to look at the reference for further details:

For a detailed description, see the ECMA-262 specification.

It is (at least, it looks to me) a claim of full compatibility and once more it makes me think to a bug, rather than a partial implementation of the specification.

So, unfortunately that is the intended way to stringify a function (it makes sense indeed, for it is an Ecmascript compliant environment), but it doesn't work correctly in QML, even though it should as stated in the documentation.

这篇关于QML - 将JS函数的代码作为字符串获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆