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

dte*_*ech 7 javascript qt function tostring qml

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

function foo() {...}
foo.toString()
Run Code Online (Sandbox Code Playgroud)

但是,在QML中这样做会让我感到很不舒服 function () { [code] }

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

Cod*_*rPi 0

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

\n\n
Function Properties\n    toString()\n    apply(thisArg, argArray)\n    call(thisArg [, arg1 [, arg2, ...]])\n    bind((thisArg [, arg1 [, arg2, \xe2\x80\xa6]])\n
Run Code Online (Sandbox Code Playgroud)\n\n

对于 JS 函数,QT 不支持获取函数字符串的其他选项。但如果你解释一下你想要它的原因,我们也许能够找到另一个解决方案。

\n