首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >goog.provide() - Uncaught :意外令牌非法

goog.provide() - Uncaught :意外令牌非法
EN

Stack Overflow用户
提问于 2014-04-06 19:04:51
回答 1查看 176关注 0票数 0

所以我今天决定和LimeJS玩一玩,我以前从来没有用过闭包,所以这对我来说也是新的。我一开始就遇到了一个小问题,我不知道出了什么问题。

到目前为止,我的项目只有三个文件:firstGame.htmlfirstGame.js、`player.js

firstGame.html:

代码语言:javascript
复制
<!DOCTYPE HTML>

<html>
<head>
    <title>firstGame</title>
    <script type="text/javascript" src="../closure/closure/goog/base.js"></script>
    <script type="text/javascript" src="firstGame.js"></script>
    <script type="text/javascript" src="player.js"></script>
</head>

<body onload="firstGame.start()"></body>

</html>

firstGame.js:

代码语言:javascript
复制
goog.provide('firstGame');


//get requirements
goog.require('lime.Director');
goog.require('lime.Scene');
goog.require('lime.Layer');
goog.require('lime.Circle');
goog.require('lime.Label');
goog.require("lime.Sprite");
goog.require('lime.animation.Spawn');
goog.require('lime.animation.FadeTo');
goog.require('lime.animation.ScaleTo');
goog.require('lime.animation.MoveTo');
goog.require("firstGame.Player");


// entrypoint
firstGame.start = function(){

    var director = new lime.Director(document.body,1024,768);
    director.makeMobileWebAppCapable();
    scene = new lime.Scene();
    var background = new lime.Sprite().setSize(1524,768).setPosition(0,0).setFill(0,0,0).setAnchorPoint(0,0);
    var player = new firstGame.Player();
    scene.appendChild(background);
    // set current scene active
    director.replaceScene(scene);

}


//this is required for outside access after code is compiled in ADVANCED_COMPILATIONS mode
goog.exportSymbol('firstGame.start', firstGame.start);

最后,player.js(这个想法是一个定制的ui组件,所以我从Sprite继承):

代码语言:javascript
复制
goog.provide("firstGame.Player');


goog.require('lime.Sprite');

// new constructor
firstGame.Player = function(){
    // call parents constructor
    goog.base(this);

    // custom initialization code
    this.color_ = 'red';
}
// define parent class
goog.inherits(firstGame.Player,lime.Sprite);

然后我运行了lime.py update (不确定是否需要,因为我只是在添加一个类,而不是一个全新的命名空间,但我认为我应该是安全的)

当我加载页面时,我得到了上面提到的意外令牌错误,这发生在player.js的第1行goog.provide()上。现在,如果我从html文件中的脚本路径中删除player.js,我发现我的其他代码运行良好,这表明我正在按预期的方式链接到闭包库。当我尝试在player.js中使用它时,我就遇到了这个问题。我的第一个倾向是,在解析闭包库之前,可能代码正在执行,在加载闭包时,我找了一些挂钩,但是找不到任何东西。我在谷歌上搜索了一下,却没有找到答案。我觉得我错过了一些简单的东西,但无法完全理解。如果有人有任何建议,我会很感激的,非常感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-06 19:08:15

代码语言:javascript
复制
goog.provide("firstGame.Player');

应该是

代码语言:javascript
复制
goog.provide('firstGame.Player');

你的qoutes不匹配。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22898573

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档