标签:selector call 思想 tor server sele 语法错误 call() bin
VC 第一版
!function(){
var view = document.querySelector(‘xxx‘)
var controller = function(view){
..… }
controller.call(null,view)
}.call()
VC 第二版,添加init
!function(){
var view = document.querySelector(‘xxx‘)
var controller = {
view: null,
init: function(view){
this.bindEvents(). //this.bindEvents().call(this)
},
bindEvents: function(){
...
… }
}
controller.init(view). //controller.init.call(controller,view)
}.call()
MVC思想完整版
!function(){
//M 数据相关的操作,负责和server数据交互
var model = {
fetch: function(){
...
},
save: function(){
...
}
}
//V 负责视图展示
var view = document.querySelector(‘xxx‘)
//C 负责逻辑等其他
var controller = {
view: null,
model: null,
init: function(view,model){
this.view = view
this.model = model
this.bindEvents()
},
bindEvents: function(){
...
}
}
controller.init(view,model)
}.call()
全局变量之间会相互骚扰。所以在代码中不要用全局变量。ES6之前只有函数里面有全局变量。
标签:selector call 思想 tor server sele 语法错误 call() bin
原文地址:https://www.cnblogs.com/nolaaaaa/p/9188865.html