zoukankan      html  css  js  c++  java
  • jquery的 $proxy() 等于 underscore的bind 等于 原生js的 bind 没毛病吧?

    见注释…………
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>jquery事件命名空间</title>
    </head>
    <body>
    <div id="tree"></div>
    </body>
    
    <script src="../lib/jquery-1.11.1.js"></script>
    <script src="../lib/underscore.js"></script>
    <script>
        var Tree = function(element, options) {
            var $tree = this.$tree = $(element);
            //监听init事件,触发
            //$tree.on('init', $.proxy(options.onInit, this));//用jquery实现 ok~~~
            //$tree.on('init',options.onInit);//什么都不写 则会报错
           // $tree.on('init',options.onInit.bind(this));//用原生bind实现 ok~~~
            $tree.on('init',_.bind(options.onInit,this));//用 underscore实现
            this.init();
        };
    
        Tree.prototype.init = function() {
            console.log('tree init!');
            this.$tree.trigger('init');
        };
    
        var tree = new Tree('#tree', {
            onInit: function() {
                console.log(this.$tree.outerHeight());
            }
        });
    </script>
    </html>
  • 相关阅读:
    python yield 理解
    创建loop设备
    git 添加submodule 以及更名
    用了linux 这么久,终于发现一个需要硬连接的地方
    gdb 查看内存
    att 汇编 helloworld
    ln 创建连接和mount -bind用法
    区间DP
    数位DP
    VS反汇编分析
  • 原文地址:https://www.cnblogs.com/WhiteHorseIsNotHorse/p/6270470.html
Copyright © 2011-2022 走看看