Use this to add events to your objects without needing any libaries.
Simple function can be imported or copy pasted. In your object constructor
assign your event functions to the return value of the createCustomEvent()
.
Simple example:
var CountdownLatch = function (limit) { | |
this.limit = limit; | |
this.count = 0; | |
this.waitBlock = function () {}; | |
}; | |
CountdownLatch.prototype.async = function (fn, ctx) { | |
var _this = this; | |
fn.call(ctx, function () { | |
_this.count = _this.count + 1; | |
if(_this.limit <= _this.count){ |
#!/bin/bash | |
## Copyright (C) 2009 Przemyslaw Pawelczyk <[email protected]> | |
## License: GNU General Public License v2, v3 | |
# | |
# Lockable script boilerplate | |
### HEADER ### | |
LOCKFILE="/var/lock/`basename $0`" |
function iAmAllDone() { | |
// Do something herebecause It's All Done! | |
} | |
function onContributionWizardAfterAddEntry(entries) { | |
for(var i = 0; i < entries.length; i++) { | |
parent.top.$j("#externalVideoID").val(entries[i].entryId); | |
} | |
// Trigger an event however the library event model handles event triggering. |
class ReadlineLoop | |
constructor: -> | |
@rl = readline.createInterface | |
input: process.stdin | |
output: process.stdout | |
@rl.on("line" , @onLine) | |
.on("close", @onClose) | |
onLine: => # ... | |
onClose: => # ... |
/** | |
* # Simple Router | |
* A JavaScript router class. | |
* | |
* #### Examples | |
* var appRouter, func, | |
* Router = require("Router"); | |
* | |
* appRouter = new Router(); | |
* appRouter.get("/", indexMethod); |
// * document is the JavaScript document object | |
// * bind adds an event listener to the document object | |
// * pageinit is the event that document object should listen for | |
// * the anonymous function is the callback that getsw executed when the | |
// document recieves the pageinit event. | |
$(document).bind("pageinit", function(){ | |
// Now the pageinit event was triggered | |
// again lets attach an event listener to the document element #listitem2 | |
// This time the event to listen for is the swipeleft event | |
// The convinience function swipeleft is the same a s bind("swipeleft",...) |
//all of this is within a pretty long method for handling key events | |
var groupChoices = { | |
65 : 'a', 66 : 'b', 67 : 'c', | |
68 : 'd', 69 : 'e', 70 : 'f', | |
71 : 'g', 72 : 'h', 73 : 'i', | |
74 : 'j', 75 : 'k', 96 : '0', | |
97 : '1', 98 : '2', 99 : '3', | |
100 : '4', 101 : '5', 102 : '6', | |
103 : '7', 104 : '8', 105 : '9' |
module Jekyll | |
require 'coffee-script' | |
class CoffeeScriptConverter < Converter | |
safe true | |
priority :normal | |
def matches(ext) | |
ext =~ /coffee/i | |
end |