组件的写成

8.20更新

quark.base.js结构很清晰,主要是一个main.js

(function(){
    window.onload = function(){
        game.init();
    };

    var game = {}

    game.init = function(){}

  //还有很多game.someFunc = function(){...} })();

在其他js,中比如掉下来的水果fruit.js,接篮子boy.js,里面的结构是:

(function(){

var Boy = game.Boy = function(props){}

Q.inherit(Boy, Q.DisplayObjectContainer);
//inherit的可能是其他的一些东西,Q.MovieClip

Boy.prototype.init = function(){}
//用到了prototype呢!!!!


})();

框架就是这个,但是具体的东西,还要再研究一下,怎么可以整体搭建起来,好赞!

关键还是quark.base啊,写个框架才是王道!

--------------------------------------------------------------------------------------------------------------------------------------

 

上一次问球,说jquery是一种方式,用函数prototype什么的,是另外一种还给看了他很早之前写的。

 其实这个就是块级作用域嘛,带个参数啥的也不吓人,为了防止变量全局污染啥的--20140714

看人家老的,两种我分不太清楚:

 

似乎fancybox满足我的要求?感觉还不错的样子!!!!!!,但是这里面的参数是干什么的?

(function (window, document, $, undefined) {
    //todo
}(window, document, jQuery));

 

 

还有这样写的,为啥呢?有啥区别?

WebcamToy.Audio = (function (c) {
}(WebcamToy));

 

 

哈根达斯camera

WebcamToy.Camera = (function () {
})()

 

lottery.js

window.homeNav = {
    open:function(){
        //开始动画
        console.log("open");
    };
    close:function(){
        //结束动画

    };
}

 

定时器 ↓

var WebcamToy = {};
WebcamToy.RuntimeTimer=function(){
    var _this=this,endtime=180,current=0,timer;

    this.update=function(){
        current=0;
    }

    this.destroy=function(){
        clearInterval(timer);
        window.location.reload();
    }

    this.start=function(){
        timer=setInterval(function(){
            current++;
            if(current>=endtime){
                _this.destroy();
            }
        },1000);
    }

    var _init=function(){

        this.start();
    }

    _init.apply(this,arguments);
}

//调用 20140917更新 拼图采用这种方式写模块
window.RuntimeTimer=new WebcamToy.RuntimeTimer(); //直接调用了_init
window.RuntimeTimer.update(); //单独调用里面的某个函数

 

posted @ 2014-06-27 11:46  星堡a  阅读(264)  评论(0编辑  收藏  举报