gpt4 book ai didi

marionette - Marionette 应用初始化程序有什么意义?

转载 作者:行者123 更新时间:2023-12-04 20:44:07 26 4
gpt4 key购买 nike

我真的不明白它们是如何有用的。原文article引入了初始化程序,这是代码示例:

App = new Backbone.Marionette.Application();

App.addInitializer(function(){
// add some app initialization code, here
});

App.addInitializer(function(){
// more initialization stuff
// for a different part of the app
});

// run all the initializers and start the app
App.start();

但是,据我所知,那^和这之间没有区别:
App = new Backbone.Marionette.Application();

// add some app initialization code, here

// more initialization stuff
// for a different part of the app

后一种代码的好处是您实际上可以控制初始化代码的顺序,而初始化程序以随机​​顺序运行。那么, addInitializer 的优势是什么? ?

最佳答案

我认为主要的胜利是语义 - 这是一个非常具有描述性的方法名称 - 以及相关功能的分组。我使用命名函数编写初始化程序,这有助于调试和描述性:

App.addInitializer(function startSomePartOfTheApp () {

});

另一个有用的特性是函数绑定(bind)到应用程序实例。这为您提供了混合初始化器的选项,这在较大的应用程序中很有用。

但最终,您可以按照您建议的方式实现相同的功能。

关于marionette - Marionette 应用初始化程序有什么意义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20986380/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com