<legend id='kwonc'><style id='kwonc'><dir id='kwonc'><q id='kwonc'></q></dir></style></legend>
    <i id='kwonc'><tr id='kwonc'><dt id='kwonc'><q id='kwonc'><span id='kwonc'><b id='kwonc'><form id='kwonc'><ins id='kwonc'></ins><ul id='kwonc'></ul><sub id='kwonc'></sub></form><legend id='kwonc'></legend><bdo id='kwonc'><pre id='kwonc'><center id='kwonc'></center></pre></bdo></b><th id='kwonc'></th></span></q></dt></tr></i><div id='kwonc'><tfoot id='kwonc'></tfoot><dl id='kwonc'><fieldset id='kwonc'></fieldset></dl></div>
    <tfoot id='kwonc'></tfoot>

    <small id='kwonc'></small><noframes id='kwonc'>

        <bdo id='kwonc'></bdo><ul id='kwonc'></ul>

      1. Backbone 和 bindAll:“func 未定义";

        Backbone and bindAll: quot;func is undefinedquot;(Backbone 和 bindAll:“func 未定义;)

          • <bdo id='h6Jt3'></bdo><ul id='h6Jt3'></ul>
            <i id='h6Jt3'><tr id='h6Jt3'><dt id='h6Jt3'><q id='h6Jt3'><span id='h6Jt3'><b id='h6Jt3'><form id='h6Jt3'><ins id='h6Jt3'></ins><ul id='h6Jt3'></ul><sub id='h6Jt3'></sub></form><legend id='h6Jt3'></legend><bdo id='h6Jt3'><pre id='h6Jt3'><center id='h6Jt3'></center></pre></bdo></b><th id='h6Jt3'></th></span></q></dt></tr></i><div id='h6Jt3'><tfoot id='h6Jt3'></tfoot><dl id='h6Jt3'><fieldset id='h6Jt3'></fieldset></dl></div>
                  <tbody id='h6Jt3'></tbody>
                  <legend id='h6Jt3'><style id='h6Jt3'><dir id='h6Jt3'><q id='h6Jt3'></q></dir></style></legend>
                • <small id='h6Jt3'></small><noframes id='h6Jt3'>

                  <tfoot id='h6Jt3'></tfoot>
                  本文介绍了Backbone 和 bindAll:“func 未定义";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在使用 bindAll 时遇到了问题.我得到的错误是 func 未定义.对我做错了什么有什么想法吗?

                  I've got problems using bindAll. The error I get is func is undefined. Any thoughts on what I'm doing wrong?

                  我都试过了

                  • bindAll(因上述错误而失败)和
                  • 单独的绑定s(不工作)
                  • bindAll (fails with the above error) and
                  • individual binds (don't work)
                  window.test = Backbone.View.extend({
                  
                    collection: null
                  
                    initialize: ->
                      console.log('initialize()')
                      console.log(this)
                      # _.bindAll(this, ["render", "foo"])
                      _.bind(this.render, this) # these don't throw errors, but binding won't work
                      _.bind(this.foo, this) 
                      @collection = new Backbone.Collection()
                      @collection.bind "add",     @render
                      @collection.bind "add",     @foo
                      @render()
                  
                    foo: ->
                      # won't be bound to the view when called from the collection
                      console.log("foo()")
                      console.log(this)
                      console.log(this.collection) # undefined (since this is the collection, not the view)
                  
                    render: ->
                      console.log("render()")
                      console.log(this)
                      return this
                  
                  })
                  testInstance = new window.test();
                  # using _.bind instead of bindAll we get past this point, however this won't be the view
                  testInstance.collection.add({})
                  

                  推荐答案

                  你使用的是 CoffeeScript,你不需要下划线的绑定.CoffeeScript 内置了它.只需使用胖箭头"

                  You are using CoffeeScript, you don't need underscore's bind. CoffeeScript has it built in. Just use "fat arrows"

                  foo: =>
                      #Your foo implementation goes here
                  render: =>
                      # your render implementation goes here
                  

                  在此处搜索胖箭头":http://jashkenas.github.com/coffee-script/

                  但是,对于 _.bindAll,您不需要将方法名称作为数组提供.您可以执行 _.bindAll(this)_.bindAll(this, 'render', 'foo') (方法名称是 var args,而不是显式列表).看看有没有帮助.

                  However, with regards to _.bindAll, you don't need to provide the method names as an array. You can do either _.bindAll(this) or _.bindAll(this, 'render', 'foo') (method names are var args, not an explicit list). See if that helps.

                  这篇关于Backbone 和 bindAll:“func 未定义";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                  getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)
                  How do I make a TextGeometry multiline? How do I put it inside a square so it wraps like html text does inside a div?(如何制作 TextGeometry 多线?如何将它放在一个正方形内,以便它像 html 文本一样包裹在 div 内?) - IT屋-程序员软件开发技术分享社
                  How to use coffeescript in developing web-sites?(如何在开发网站时使用coffeescript?)

                  <small id='HHXQv'></small><noframes id='HHXQv'>

                        <bdo id='HHXQv'></bdo><ul id='HHXQv'></ul>
                      • <tfoot id='HHXQv'></tfoot>
                      • <legend id='HHXQv'><style id='HHXQv'><dir id='HHXQv'><q id='HHXQv'></q></dir></style></legend>
                            <i id='HHXQv'><tr id='HHXQv'><dt id='HHXQv'><q id='HHXQv'><span id='HHXQv'><b id='HHXQv'><form id='HHXQv'><ins id='HHXQv'></ins><ul id='HHXQv'></ul><sub id='HHXQv'></sub></form><legend id='HHXQv'></legend><bdo id='HHXQv'><pre id='HHXQv'><center id='HHXQv'></center></pre></bdo></b><th id='HHXQv'></th></span></q></dt></tr></i><div id='HHXQv'><tfoot id='HHXQv'></tfoot><dl id='HHXQv'><fieldset id='HHXQv'></fieldset></dl></div>
                              <tbody id='HHXQv'></tbody>