{"action":"created","issue":{"url":"https://api.github.com/repos/LeaVerou/bliss/issues/183","repository_url":"https://api.github.com/repos/LeaVerou/bliss","labels_url":"https://api.github.com/repos/LeaVerou/bliss/issues/183/labels{/name}","comments_url":"https://api.github.com/repos/LeaVerou/bliss/issues/183/comments","events_url":"https://api.github.com/repos/LeaVerou/bliss/issues/183/events","html_url":"https://github.com/LeaVerou/bliss/issues/183","id":149478423,"number":183,"title":"Calling a `$.add` plugin from $$() ","user":{"login":"thany","id":152227,"avatar_url":"https://avatars.githubusercontent.com/u/152227?v=3","gravatar_id":"","url":"https://api.github.com/users/thany","html_url":"https://github.com/thany","followers_url":"https://api.github.com/users/thany/followers","following_url":"https://api.github.com/users/thany/following{/other_user}","gists_url":"https://api.github.com/users/thany/gists{/gist_id}","starred_url":"https://api.github.com/users/thany/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thany/subscriptions","organizations_url":"https://api.github.com/users/thany/orgs","repos_url":"https://api.github.com/users/thany/repos","events_url":"https://api.github.com/users/thany/events{/privacy}","received_events_url":"https://api.github.com/users/thany/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-04-19T14:32:07Z","updated_at":"2016-04-23T23:59:44Z","closed_at":"2016-04-23T23:59:44Z","body":"I would be cool to be able to call a plugin on a `$$(...)` selector, that was added via `$.add` where the `this` variable in that plugin would correspond to the **array** of elements, rather than it getting called for each item one by one.\r\n\r\nSo consider:\r\n```\r\n$.add(\"myplugin\", function() {\r\n  console.log(this);\r\n});\r\n\r\n$$(\"div\")._.myplugin();\r\n```\r\nI would like to have the logged `this` in this example to be the array that contains all divs. perhaps as an option to `$.add`.\r\n\r\nThe reason for this is a more efficient way to define more complex plugins, like so:\r\n```\r\n$.add(\"myplugin\", function() {\r\n  // some shared stuff here, like event handlers, data, whatever\r\n\r\n  this.forEach(function(element) {\r\n    // do something per element here\r\n  });\r\n});\r\n```\r\nThis works fine when called element by element, however all \"shared stuff\" will be reinitialized on each call, which is less efficient than calling this plugin once.\r\n\r\nOn the other side, as some may not realize, it is possible to rewrite such a plugin to have once-initialized data, without any change to Bliss. But I don't think it will be an obvious solution and such code may look slightly too obnoxious for novice programmers:\r\n```\r\n$.add(\"myplugin\", (function() {\r\n  // some shared stuff here\r\n\r\n  return function() {\r\n    // do something per element here\r\n  };\r\n}()));\r\n```\r\nI'm not sure which is the best approach. One is more similar to jQuery, which might appeal more to novice programmers, while the other probably works fine, but requires more rewriting work when coming from jQuery and might not appeal to novice folks as much."},"comment":{"url":"https://api.github.com/repos/LeaVerou/bliss/issues/comments/213854315","html_url":"https://github.com/LeaVerou/bliss/issues/183#issuecomment-213854315","issue_url":"https://api.github.com/repos/LeaVerou/bliss/issues/183","id":213854315,"user":{"login":"LeaVerou","id":175836,"avatar_url":"https://avatars.githubusercontent.com/u/175836?v=3","gravatar_id":"","url":"https://api.github.com/users/LeaVerou","html_url":"https://github.com/LeaVerou","followers_url":"https://api.github.com/users/LeaVerou/followers","following_url":"https://api.github.com/users/LeaVerou/following{/other_user}","gists_url":"https://api.github.com/users/LeaVerou/gists{/gist_id}","starred_url":"https://api.github.com/users/LeaVerou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LeaVerou/subscriptions","organizations_url":"https://api.github.com/users/LeaVerou/orgs","repos_url":"https://api.github.com/users/LeaVerou/repos","events_url":"https://api.github.com/users/LeaVerou/events{/privacy}","received_events_url":"https://api.github.com/users/LeaVerou/received_events","type":"User","site_admin":false},"created_at":"2016-04-23T23:59:44Z","updated_at":"2016-04-23T23:59:44Z","body":"Yup! Closing this now, for tidyness. :)"}}