sdc*_*sdc 2 javascript safari javascriptcore
当我使用系统库中提供的JSC(JavaScriptCore)引擎时,它的行为与使用Safari的调试控制台时不同
$ /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc
>>> console.log("hello");
Exception: TypeError: undefined is not an object (evaluating 'console.log')
Run Code Online (Sandbox Code Playgroud)
当console.log("hello");在Safari中工作完全正常.
TL; DR
var Console = function () {
this.log = function(msg){ debug(msg) };
};
var console = new Console();
console.log("hello");
Run Code Online (Sandbox Code Playgroud)
Safari创建一个控制台对象,该对象在调试控制台中可用,但在JSC环境中不可用.请在此处查看Safari的控制台文档
添加我自己的包装JSC调试方法的控制台对象解决了我的问题:
$ /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc
>>> var Console = function () {
... this.log = function(msg){ debug(msg) };
... };
undefined
>>> var console = new Console();
undefined
>>> console.log("hello");
-> hello
undefined
Run Code Online (Sandbox Code Playgroud)