• 看似递归的不是递归,是缓存之前的函数


    看似递归的不是递归,是缓存之前的函数

    (function () {
        var Button = function(label, color){
            this.initialize(label, color);
        };
        var p = Button.prototype = new createjs.Container();
        p.label;
        p.background;
        p.count = 0;
        
        p.Container_initialize = p.initialize; // 这个是缓存之前的函数;
        p.initialize = function(label,color){  //重新定义了这个函数; 
            this.Container_initialize();       //调用了之前缓存的函数
            this.label = label;
            if(!color) {
                color ='#ccc';
            }
            
            var text = new createjs.Text(label, '20px Arial','#000');
            text.textBaseline = 'top';
            text.textAlign = 'center';
            
            var width = text.getMeasuredWidth() + 30;
            var height = text.getMeasuredHeight() + 20;
            
            this.background = new createjs.Shape();
            this.background.graphics.beginFill(color).drawRoundRect(0,0,width,height,10);
            
            text.x = width /2;
            text.y = 10;
            
            this.addChild(this.background, text);
            this.on('click', this.handleClick);
            this.on('tick', this.handleTick);
            
            this.mouseChildren = false;
        };
        
        p.handleClick = function(event){
            var target = event.target;
            alert('You clicked on a button: '+ target.label);
        };
        
        p.handleTick = function (event) {
            p.alpha = Math.cos(p.count++*0.1)*0.4+0.6;
        };
        
        window.Button = Button;
    }());
  • 相关阅读:
    Linux学习总结(18)——Linux使用init命令关机、重启、切换模式
    iOS autorelease使用详解
    iOS xib的使用详解
    iOS ASI--缓存
    iOS ASI--其他用法
    iOS ASI--管理多个请求
    iOS ASI--文件上传
    iOS ASI--文件下载
    iOS ASI--POST请求
    iOS ASI--GET请求
  • 原文地址:https://www.cnblogs.com/stono/p/5566748.html
Copyright © 2020-2023  润新知