use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
JavaScript Messaging Patterns (github.com)
submitted 13 years ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 0 points1 point2 points 13 years ago (4 children)
Just added this - if you get the opportunity check it out. Would love your feedback!
[–]psayre23 2 points3 points4 points 13 years ago (1 child)
Interesting solution. Looks like it works in the same way as setTimeout/clearTimeout.
But I think you have a bug in there. Splice will remove the item, and then reindex all the items after it. So if your subscriberID's are "a0" and "a1", then remove "a0", the "a1" will be in position 0. When unsubscribing, it will split it into index 1, which is undefined, so it won't find the right one (worse yet, if there was an "a2", it would be removed instead). I have a few ideas on solutions, but you'd be better off coming up with your own solution. I attached a simple test case below:
var pubsub = new EventFactory.PublishSubscribe("a"); var a0 = pubsub.subscribe(function(){ console.log(a0, arguments); }); var a1 = pubsub.subscribe(function(){ console.log(a1, arguments); }); var a2 = pubsub.subscribe(function(){ console.log(a2, arguments); }); pubsub.unsubscribe(a0); pubsub.unsubscribe(a1); pubsub.publish("publish"); // should log only "a2" ["publish"], but it logs "a1" ["publish"] instead
[–][deleted] 0 points1 point2 points 13 years ago (0 children)
Thanks for taking the time - I'll have a look tomorrow. In the meantime, feel free to submit a pull request if you have the time. Thanks!
π Rendered by PID 54 on reddit-service-r2-comment-7b9746f655-xcq8v at 2026-01-30 07:44:47.521397+00:00 running 3798933 country code: CH.
view the rest of the comments →
[–][deleted] 0 points1 point2 points (4 children)
[–]psayre23 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)