var _json = [{"codigo": "1", "nome": "Robert Santos", "turma": "EM2A"}, {"codigo": "2", "nome": "Eduardo Alves Silveira", "turma": "EM3A"}, {"codigo": "3", "nome": "Amara Gouveia", "turma": "EMT2B"}, {"codigo": "4", "nome": "Tainá Belchior da Silva", "turma": "EF5B"}];
function console() {
console.log(JSON.stringify(_json, null, 4));
}
console();
您好,我正在使用此代码,但是当我尝试执行console()
时,出现此错误:TypeError: console.log is not a function
我该怎么做才能解决此问题?
答案 0 :(得分:5)
之所以得到obj.position
,是因为您用自己的名为var obj = new THREE.Mesh(
new THREE.PlaneGeometry(3, 2, 1, 1),
new THREE.MeshLambertMaterial({color:0x00aa00,transparent:true,side:THREE.DoubleSide})
);
obj.geometry.translate(3,2,0);
obj.position.copy(new THREE.Vector3(3.0, 2, 0.0));
var box = new THREE.Box3().setFromObject( obj );
box.getCenter( obj.position ); // this re-sets the obj position
obj.geometry.center();
的函数覆盖了TypeError: console.log is not a function
对象,而该函数没有console
函数。您可以通过将函数重命名为其他内容来解决此问题,如代码段示例:
console
答案 1 :(得分:0)
全局window
对象已经具有一个名为console
的函数,您正在尝试使用自己的console
函数覆盖该函数。只需将您的console
函数重命名为其他名称即可。
答案 2 :(得分:0)
您无法命名函数console
原因-Console
是JavaScript中的现有对象,可用于访问浏览器的调试控制台。阅读MDN web docs了解更多信息
更正的代码
var _json = [{"codigo": "1","nome": "Robert Santos","turma": "EM2A"},
{"codigo": "2","nome": "Eduardo Alves Silveira","turma": "EM3A"},{"codigo":
"3","nome": "Amara Gouveia","turma": "EMT2B"},{"codigo": "4","nome": "Tainá Belchior da Silva","turma": "EF5B"}];
function logger() {
console.log(JSON.stringify(_json, null, 4));
}
logger();