我正在写一个插件.为此,我将记录一些事情,说警告,necc事情等.要记录它们我将使用控制台,但如果某些浏览器不支持控制台可能会出错.要处理此错误,我正在考虑使用此代码:
if (typeof console == 'undefined') console = {};
if (typeof console.log == 'undefined') console.log = function() {};
if (typeof console.debug == 'undefined') console.debug = function() {};
if (typeof console.info == 'undefined') console.info = function() {};
if (typeof console.warn == 'undefined') console.warn = function() {};
if (typeof console.error == 'undefined') console.error = function() {};
Run Code Online (Sandbox Code Playgroud)
这项工作是正确还是有更好的选择?