// jQuery
$(document).ready(function() {
// code
})
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Object.prototype.emit = function(name, d) { | |
| this.dispatchEvent(new CustomEvent(name, { detail: d })); | |
| return this; | |
| }; | |
| Object.prototype.on = function(name, cb) { | |
| this.addEventListener(name, cb, false); | |
| return cb; | |
| }; | |
| Object.prototype.once = function(name, cb) { | |
| var wrapper = function() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. | |
| * @license GNU General Public License version 2 or later; see LICENSE | |
| */ | |
| namespace Joomla\Data; | |
| use Psr\Cache\CacheInterface; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var pubsub = function(l, u, r, i) { // cool! 闭包并且初始化vars | |
| return function(n, f) { | |
| r = l[n] = l[n] || [], i = -1; | |
| if (f && f.call) r.push(f); | |
| else while (r[++i]) r[i].apply(u, arguments); | |
| } | |
| }({}); | |
| // subscribe to event | |
| pubsub("eat_cookie", function() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Lightweight PUBLISH / SUBSCRIBE Class | |
| Original code from: <http://blog.bobcravens.com/2011/01/loosely-coupled-javascript-using-pubsub/> | |
| Can be initialized on other Objects to provide pub/sub functionality within that object | |
| ex: this.events = new PubSub(); | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Expected Result: | |
| ---------------- | |
| One | |
| Two | |
| Three | |
| Four | |
| Six |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Open your console. | |
| <script src="event-source.js"></script> |
NewerOlder