Git Product home page Git Product logo

mitter's Introduction

mitter.js

一个实现发布订阅/eventbus基础功能的练习Demo

当我尝试实现时遇到的问题

  1. 为什么两次impor导入后,共享的对象却相同?

答 : import的执行是将代码静态引入,两次引入应该生成两个互不关联的作用域,事实上也确实如此。 之所以能够共享同一个对象,是因为node的模块机制,我们的代码最后如果打包到同一个chunk中,那么实际上mitt仅仅只执行了一次,而mitt内部会挂载一个全局对象,故而能够两次导入却共享同一对象内容,完成跨组件的发布和订阅.

文件结构描述

文件名描述 描述
a.js 模块
b.js 模块
bus.js 事件中心
mitter.js 订阅发布工具
x.js 模块

使用

mitter.add(事件名,函数) mitter.exec(事件名,参数)

mitter's People

Contributors

eq1024 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.