201505092150_ "javascript mode-Viewer mode"

Source: Internet
Author: User

1. Definition

Events = function () {             var listen, log, obj, one, remove, trigger, __this;             obj = {};             __this = this ;             listen = function ( key, eventfn ) {  //把简历扔盒子, key就是联系方式.               var stack, _ref;  //stack是盒子               stack = ( _ref = obj[key] ) != null ? _ref : obj[ key ] = [];               return stack.push( eventfn );             };             one = function ( key, eventfn ) {               remove( key );               return listen( key, eventfn );             };             remove = function ( key ) {               var _ref;               return ( _ref = obj[key] ) != null ? _ref.length = 0 : void 0;             };             trigger = function () {  //面试官打电话通知面试者               var fn, stack, _i, _len, _ref, key;               key = Array.prototype.shift.call( arguments );               stack = ( _ref = obj[ key ] ) != null ? _ref : obj[ key ] = [];               for ( _i = 0, _len = stack.length; _i < _len; _i++ ) {                 fn = stack[ _i ];                 if ( fn.apply( __this,  arguments ) === false ) {                   return false ;                 }               }               return {                  listen: listen,                  one: one,                  remove: remove,                  trigger: trigger               }             }2. Use var adultTv = Event(); adultTv .listen(  ‘‘ play ‘,  function( data ){     alert ( "今天是谁的电影" + data.name ); }); //发布者 adultTv .trigger(  ‘ ‘play‘ ,  { ‘name‘ : ‘麻生希‘ }  );

201505092150_ "javascript mode-Viewer mode"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.