-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
12月第三周 #2
Comments
1. 建立需求
2. 经过分析后得到技术解决方案
3. 建立思想由于状态必须保持实时监测,所以分析得知用window.setInterval进行实时监测4. 如何组织我们的代码由于对技术做好选型使用两个api解决这个需求 首先建立检测程序 window.setInterval(function(){
// do something
},1000);
var navigator = window.navigator ; 我们可以把这两个底层提供的基础功能进行组织 window.setInterval(function(){
// do something
var navigator = window.navigator ;
if(navigator.onLine){
// online
}
else{
// offline
}
},1000); 以上基础组织已经完工,但只算个半成品功能 再次组织代码 (function(win,$){
var NSApi= win.NSApi = function(elem,delay){
this.elem = elem ; // root element
this.delay = delay || 3000 ; // time delay
this.start() ; // start init
} ;
function getStatusValue(){
} ;
NSApi.prototype.start = function(){
window.setInterval(function(){
var self = this ;
var navigator = window.navigator ;
var boolOnLine = navigator.onLine ;
if(boolOnLine){
self.elem.trigger("ns.online",boolOnLine) ;
}
else{
self.elem.trigger("ns.offline",boolOnLine) ;
}
},1000) ;
} ;
NSApi.prototype.pubsub = function(){
return this.elem ;
} ;
})(window,jQuery); 建立客户端代码 $(function(){
var nsMain = $("#nsMain") ;
new NSApi(nsMain,1000).pubsub().on("ns.online",function(isOnline){
nsMain.text("用户在线") ;
console.log((isOnline)) ;
}).on("ns.offline",function(isOnline){
nsMain.text("用户离线") ;
console.log((isOnline)) ;
}) ;
}); html片段 <div id="nsMain"></div> 5,最后总结建语音讨论相关注意事项6,课后题目实现一个简单的选项卡功能理解pubsub机制 |
课堂记录 :有关封装 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2015/12/20 22:00-23:00 VaJoy - 《高性能js》第八章剖析
2015/12/17 21:30-23:00 大熊 - h5的online/offline
The text was updated successfully, but these errors were encountered: