Search code examples
javascriptbackbone.jsbackbone-layout-manager

Difference between Backbone.Layout.extend and Backbone.view.extend


So I have got this new project which has this line in every view.

Backbone.Layout.extend({ /*...*/ })

But when I look at the documentation for Backbone and other tutorials, it has

Backbone.View.extend({ /*...*/ })

Also all the views have initialize, serialize, afterRender functions. I tried searching it, but has not found anything useful.


Solution

  • Your project is using backbone.layoutmanager

    Provides a logical foundation for assembling layouts and views within Backbone. Designed to be adaptive and configurable for painless integration. Well tested, with full code coverage, in both the browser and Node.js environments.

    Looking in the source of this library, we can see that it's just a specialized Backbone.View.

    var LayoutManager = Backbone.View.extend({ // line 53
    // ...
    });
    // ...
    // Expose through Backbone object.
    Backbone.Layout = LayoutManager; // line 955
    

    It adds these methods and properties:

    • afterRender
    • cleanup
    • getView
    • getViews
    • insertView
    • insertViews
    • removeView
    • renderViews
    • setView
    • setViews
    • then
    • useRAF
    • serialize (not documented in the wiki)

    The initialize function is a default in a Backbone view, it is empty and it's meant to be overriden with custom initialization code.

    To get a better understanding of what's going on in a project, look at the dependencies it loads (the .js files included with <script> tags in the HTML).