Skip to content

Instantly share code, notes, and snippets.

@ded
Created November 19, 2011 00:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ded/1378205 to your computer and use it in GitHub Desktop.
Save ded/1378205 to your computer and use it in GitHub Desktop.
ender delay()
!function ($) {
$.ender({
delay: function (n) {
var mock = {}
, chain = []
, key
, $el = $(this)
for (key in $el) {
if (isFinite(key)) continue
!function (key) {
mock[key] = function () {
chain.push({key:key,arguments:arguments})
return mock
}
}(key)
}
setTimeout(function () {
for (var i = 0; i < chain.length; i++) {
$el = $el[chain[i].key].apply($el, chain[i].arguments)
}
}, n)
return mock
}
}, true)
}(ender);
$('p').css('color', 'red').delay(100).addClass('a').hide().delay(200).fadeIn()
@rvagg
Copy link

rvagg commented Nov 19, 2011

_chain is on mockObj rather than being a separate variable for a special reason?
$el should probably be var $el I'm guessing.
&, lastly, the additional function inside the first loop seems a bit heavy handed to me, if it's just to get a copy of key perhaps something like key:''+key would do that without the overhead of a new function each time?
Interesting idea though. Tests for it would look pretty funky.
I dunno if you wanted public comment on this or not but there you go! Couldn't help myself.

@ded
Copy link
Author

ded commented Nov 19, 2011

you have way too much time on your hand. this was meant to send to a coworker as a simple proof of concept

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment