What's the difference between initialize and constructor on a backbone model

后端 未结 2 1056
攒了一身酷
攒了一身酷 2020-12-12 23:43

What\'s the difference between initialize and constructor on a backbone model.

When I extend a backbone model (ParentModel) I use the initialize method to set any de

2条回答
  •  悲&欢浪女
    2020-12-12 23:58

    constructor runs before Backbone sets up the structure. initialize is called inside the structure's constructor function. So basically if you need to augment anything before Backbone sets up the structure, use constructor if you need to augment anything after Backbone sets up the structure use initialize.

    (from a Github discussion on the subject)

提交回复
热议问题