当前位置: 首页 > news >正文

爱站攻略免费制作网页平台

爱站攻略,免费制作网页平台,杭州 网站开发公司,网站有哪些区别是什么定义 WxNotificationCenter.js 文件; /*** author: Di (微信小程序开发工程师)* organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)* 垂直微信小程序开发交流社区* * github地址: https://github.com/icindy/WxNotificationCenter…

定义 WxNotificationCenter.js  文件; 

/*** author: Di (微信小程序开发工程师)* organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)*               垂直微信小程序开发交流社区* * github地址: https://github.com/icindy/WxNotificationCenter* * for: 微信小程序通知广播模式类,降低小程序之间的耦合度* detail : http://weappdev.com/t/wxnotificationcenter/233*/
//   存放
var __notices = [];
var isDebug = true;
/*** addNotification* 注册通知对象方法* * 参数:* name: 注册名,一般let在公共类中* selector: 对应的通知方法,接受到通知后进行的动作* observer: 注册对象,指Page对象*/
function addNotification(name, selector, observer) {if (name && selector) {if(!observer){// ("addNotification Warning: no observer will can't remove notice");}var newNotice = {name: name,selector: selector,observer: observer};addNotices(newNotice);} else {}
}/*** 仅添加一次监听* * 参数:* name: 注册名,一般let在公共类中* selector: 对应的通知方法,接受到通知后进行的动作* observer: 注册对象,指Page对象*/
function addOnceNotification(name, selector, observer) {if (__notices.length > 0) {for (var i = 0; i < __notices.length; i++) {var notice = __notices[i];if (notice.name === name) {if (notice.observer === observer) {return;}}}}this.addNotification(name, selector, observer)
}function addNotices(newNotice) {// if (__notices.length > 0) {//     for (var i = 0; i < __notices.length; i++) {//         var hisNotice = __notices[i];//         //当名称一样时进行对比,如果不是同一个 则放入数组,否则跳出//         if (newNotice.name === hisNotice.name) {//             if (!cmp(hisNotice, newNotice)) {//                 __notices.push(newNotice);//             }//             return;//         }else{//             __notices.push(newNotice);//         }//     }// } else {// }__notices.push(newNotice);
}/*** removeNotification* 移除通知方法* * 参数:* name: 已经注册了的通知* observer: 移除的通知所在的Page对象*/function removeNotification(name,observer) {for (var i = 0; i < __notices.length; i++){var notice = __notices[i];if(notice.name === name){if(notice.observer === observer){__notices.splice(i,1);return;}}}}/*** postNotificationName* 发送通知方法* * 参数:* name: 已经注册了的通知* info: 携带的参数*/function postNotificationName(name, info) {if(__notices.length == 0){return;}for (var i = 0; i < __notices.length; i++){var notice = __notices[i];if(notice.name === name){notice.selector(info);}}}// 用于对比两个对象是否相等
function cmp(x, y) {// If both x and y are null or undefined and exactly the same  if (x === y) {return true;}// If they are not strictly equal, they both need to be Objects  if (! (x instanceof Object) || !(y instanceof Object)) {return false;}// They must have the exact same prototype chain, the closest we can do is  // test the constructor.  if (x.constructor !== y.constructor) {return false;}for (var p in x) {// Inherited properties were tested using x.constructor === y.constructor  if (x.hasOwnProperty(p)) {// Allows comparing x[ p ] and y[ p ] when set to undefined  if (!y.hasOwnProperty(p)) {return false;}// If they have the same strict value or identity then they are equal  if (x[p] === y[p]) {continue;}// Numbers, Strings, Functions, Booleans must be strictly equal  if (typeof(x[p]) !== "object") {return false;}// Objects and Arrays must be tested recursively  if (!Object.equals(x[p], y[p])) {return false;}}}for (p in y) {// allows x[ p ] to be set to undefined  if (y.hasOwnProperty(p) && !x.hasOwnProperty(p)) {return false;}}return true;
};module.exports = {addNotification: addNotification,removeNotification: removeNotification,postNotificationName: postNotificationName,addOnceNotification: addOnceNotification
}

在需要的页面js中引入该文件

var WxNotificationCenter = require("../../utils/WxNotificationCenter.js");// 广播:WxNotificationCenter.postNotificationName('广播的名字', '');    // 监听var that = this;WxNotificationCenter.addNotification('广播的名字', that.'要调用的方法' , that);

http://www.hkea.cn/news/772347/

相关文章:

  • 网站要怎么做才能让360收录推广品牌的策划方案
  • 做网站前景营销课程培训视频
  • 青海做网站广告开户南京seo
  • wordpress写软文赚钱seo快速培训
  • 南宁网站建设接单陕西省人民政府
  • wordpress网站价格seo域名综合查询
  • 支付网站怎么做的网络自动推广软件
  • js做网站统计品牌关键词优化
  • 微信公众号管理平台官网谷歌seo建站
  • 鲜花购物网站源码企业网站营销的优缺点
  • 表白网站制作在线日照网站优化公司
  • 企业网站建设策划书 前言徐州关键词优化排名
  • 一级a做爰片视频网站全国新闻媒体发稿平台
  • 唐山网站建设哪家专业高德北斗导航
  • wordpress 地址 .html企业网站seo贵不贵
  • 提供网站制作公司哪家好网络软文范文
  • 做原型网站枣庄网络推广seo
  • 品牌网站开发设计外贸网站平台
  • 网站做留言板网站推广在线
  • 长春服务好的网络营销seo网站推广的主要目的
  • 搜索引擎优化和关键词竞价广告的区别宿州百度seo排名软件
  • 一搜同志网站建设电话青岛网站seo优化
  • 官方做任务网站网络营销公司注册找哪家
  • django做视频网站网络营销推广专家
  • 国外手做网站搜索引擎推广的关键词
  • 网站建设商标注册多少类目域名注册免费
  • 哪里有网站设计公司长沙网络公司最新消息
  • 试描述一下网站建设的基本流程百度怎么发布短视频
  • 我现在有域名怎么做网站搜索关键词热度
  • 海外如何 淘宝网站建设快速seo整站优化排行