zoukankan      html  css  js  c++  java
  • 看似递归的不是递归,是缓存之前的函数

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

    (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;
    }());
  • 相关阅读:
    LeetCode: LRU Cache
    LeetCode: Reorder List
    LeetCode: Linked List Cycle I && II
    LeetCode: Word Break I && II
    LeetCode: Single Number I && II
    太坑了,mybatis注解一对多,id没了
    ajax请求参数的格式
    查询结果拼接
    id拼接保存到单个字段后作为表连接的查询条件
    seam的定时轮巡
  • 原文地址:https://www.cnblogs.com/stono/p/5566748.html
Copyright © 2011-2022 走看看