<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 未定义";

        时间:2024-04-19

          • <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 未定义";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Javascript代码执行顺序异常 下一篇:grunt-contrib-handlebars - 输出与我运行把手 npm 任务时不同

                  相关文章

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

                      <bdo id='HHXQv'></bdo><ul id='HHXQv'></ul>
                  1. <tfoot id='HHXQv'></tfoot>
                  2. <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>