QML - 将JS函数的代码作为字符串

时间:2015-11-21 20:51:07

标签: javascript qt function qml tostring

似乎可以在JavaScript中获取函数的代码,并且它很简单:

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

然而,在QML中这样做会给我一个相当没有吸引力的function () { [code] }

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

1 个答案:

答案 0 :(得分:0)

http://doc.qt.io/qt-5/qtqml-javascript-functionlist.html#function-objects

Function Properties
    toString()
    apply(thisArg, argArray)
    call(thisArg [, arg1 [, arg2, ...]])
    bind((thisArg [, arg1 [, arg2, …]])

对于JS函数,QT不支持获取函数字符串的其他选项。但如果你解释为什么你想要它,我们可以找到另一种解决方案。