我不明白为什么我在使用 Firebug 2.0.7 的 Firefox 34 中出现以下控制台错误。这是一个简单的代码块。它在 Safari、Chrome 和 IE 中运行良好。
"Error: Permission denied to access property 'category' myscript.js (line 7)"
var MyMaterials = function() {
var category, material;
return console.dir(this);
}
record_1 = new MyMaterials;
record_1.category = "Clear Film";
record_1.material = "Opticlear PC 5000";
console.log(record_1.category);
console.log(record_1.material);
最佳答案
解决方法很简单。停止返回 console.dir(this)
。
当您在构造函数中返回一个非基本类型时,您将获得该值而不是对象实例。 console.dir
返回一些不是对象实例的其他对象并抛出此错误,至少在 Firebug 中无论如何, native 开发人员工具似乎没有此问题。
固定代码:
var MyMaterials = function() {
var category, material;
console.dir(this);
}
record_1 = new MyMaterials;
record_1.category = "Clear Film";
record_1.material = "Opticlear PC 5000";
console.log(record_1.category);
console.log(record_1.material);
关于javascript - 错误 : Permission denied to access property 'category' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27477525/