Javascript 为什么会出现错误,“UncaughtTypeError:undefined不是函数”?
我查找了不匹配的大括号,但仍然无法找出为什么该行显示错误:lab3.init$'viewport';在HTML中 HTML:Javascript 为什么会出现错误,“UncaughtTypeError:undefined不是函数”?,javascript,jquery,three.js,Javascript,Jquery,Three.js,我查找了不匹配的大括号,但仍然无法找出为什么该行显示错误:lab3.init$'viewport';在HTML中 HTML: 包含脚本的顺序 <script src="http://code.jquery.com/jquery-2.1.0.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/three.js/r61/three.js"></script> <scri
包含脚本的顺序
<script src="http://code.jquery.com/jquery-2.1.0.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/three.js/r61/three.js"></script>
<script src="js/graphics.js"></script>
jQuery应该始终放在第一位
如果您的JS引用了插件或库,那么引用的插件或库应该包含在前面。在html中的什么地方包含javascript?在标题后面:在jquery.JS之后包含graphic.JS。@Shaunak D,这很有效!非常感谢。
(function ( lab3 , $, undefined) {
lab3.init = function(hook) {
var WIDTH = 600,
HEIGHT = 500;
var renderer = new THREE.WebGLRenderer();
renderer.setSize(WIDTH, HEIGHT);
hook.append(renderer.domElement);
var scene = new THREE.Scene();
var pointLight =
new THREE.PointLight(0xFFFFFF);
pointLight.position = new THREE.Vector3(-10, 100, 100);
scene.add(pointLight);
var VIEW_ANGLE = 65, //65 FOV is most 'natural' FOV
ASPECT = WIDTH / HEIGHT,
NEAR = 0.1, //these elements are needed for cameras to
FAR = 10000; //partition space correctly
var camera =
new THREE.PerspectiveCamera(
VIEW_ANGLE,
ASPECT,
NEAR,
FAR);
camera.position.z = 300;
scene.add(camera);
var material =
new THREE.MeshLambertMaterial(
{
color: 0x00bbcc
});
var cube = new THREE.Mesh(
new THREE.CubeGeometry(
40, 55, 30),
material);
scene.add(cube);
function renderLoop() {
renderer.render(scene, camera);
window.requestAnimationFrame(renderLoop);
}
window.requestAnimationFrame(renderLoop);
}
})(window.lab3 = window.lab3 || {} , jQuery)
<script src="http://code.jquery.com/jquery-2.1.0.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/three.js/r61/three.js"></script>
<script src="js/graphics.js"></script>