sencha中launch以及之前的活动

今天写程序的时候遇到一个麻烦,就是我在application中定义了一个变量,发现在controller中使用的时候报错说未定义。感觉是作用域问题。虽然别人说不加var就是全局变量我也将信将疑,但是这次我决定好好探究一下sencha touch在程序开始运行时所进行的一系列活动。


看官方文档上对application的launch过程的四个主要阶段的描述:

Launching

There are 4 main phases in your Application's launch process, 2 of which are inside Controller. Firstly, each Controller is able to define an initfunction, which is called before the Application launch function. Secondly, after the Application and Profile launch functions have been called, the Controller's launch function is called as the last phase of the process:

  1. Controller#init functions called
  2. Profile#launch function called
  3. Application#launch function called
  4. Controller#launch functions called

Most of the time your Controller-specific launch logic should go into your Controller's launch function. Because this is called after the Application and Profile launch functions, your app's initial UI is expected to be in place by this point. If you need to do some Controller-specific processing before app launch you can implement a Controller init function.




说的意思就是程序的launch过程主要分四个阶段,分别按顺序是controller的init,然后是profile的launch,application的launch,最后是controller的launch,这便是launch的过程。

首先我要说明一点的是,看看官方的文档,会发现,Ext.application其实是controller的子类,所以这有点违背我们的逻辑。


那么controller的这两个函数的主要作用是什么呢?看下面的文档:


 : Function

Called by the Controller's application to initialize the Controller. This is always called before the Application launches, giving the Controller a chance to run any pre-launch logic. See also launch, which is called after the Application's launch function

Ext.app.Controller
view source
 : Function

Called by the Controller's application immediately after the Application's own launch function has been called. This is usually a good place to run any logic that has to run after the app UI is initialized. See also init, which is called before the Application's launch function.


如上所术,init函数主要为程序launch之前提供一个运行代码的地方,launch的主要作用是为ui初始化之后提供一个运行代码的地方。那么profile这个我们就很熟悉了。profile不是controller的子类,所以没有init,但是它有launch。多个controller的init和launch是按照在application中的controllers数组的声明顺序执行的,把所有的init函数执行完毕后才会开始执行launch。


我在这里要探讨的主要问题不是launch过程,而是程序如何加载那些view,controller,以及models等。是不是按照applicaition中的声明顺序呢?

要知道,sencha中也是一个个类,在这些view等文件夹中存放的都是一个个类的文件。application也是一个类。当我们从index.html中载入app.js和sencha的库文件之后,我们就进入了app.js。js是顺序执行,Ext.omReady是在application之前执行。最后进入application。我做了一个实验,在每一个view文件及其其他文件的头部放上alert声明,发现这些alert出现的顺序并不是application的声明顺序。所以这是无序的,但是sencha到底是怎么加载这些脚本文件的我还没弄清楚,需要进一步研究,有兴趣可以加qq731987620

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值