{"action":"created","issue":{"url":"https://api.github.com/repos/AceMetrix/jquery-deparam/issues/20","labels_url":"https://api.github.com/repos/AceMetrix/jquery-deparam/issues/20/labels{/name}","comments_url":"https://api.github.com/repos/AceMetrix/jquery-deparam/issues/20/comments","events_url":"https://api.github.com/repos/AceMetrix/jquery-deparam/issues/20/events","html_url":"https://github.com/AceMetrix/jquery-deparam/pull/20","id":123116706,"number":20,"title":"Making jQuery dependency optional","user":{"login":"patsissons","id":5505280,"avatar_url":"https://avatars.githubusercontent.com/u/5505280?v=3","gravatar_id":"","url":"https://api.github.com/users/patsissons","html_url":"https://github.com/patsissons","followers_url":"https://api.github.com/users/patsissons/followers","following_url":"https://api.github.com/users/patsissons/following{/other_user}","gists_url":"https://api.github.com/users/patsissons/gists{/gist_id}","starred_url":"https://api.github.com/users/patsissons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/patsissons/subscriptions","organizations_url":"https://api.github.com/users/patsissons/orgs","repos_url":"https://api.github.com/users/patsissons/repos","events_url":"https://api.github.com/users/patsissons/events{/privacy}","received_events_url":"https://api.github.com/users/patsissons/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-12-19T23:39:21Z","updated_at":"2015-12-20T20:19:52Z","closed_at":"2015-12-20T20:00:04Z","pull_request":{"url":"https://api.github.com/repos/AceMetrix/jquery-deparam/pulls/20","html_url":"https://github.com/AceMetrix/jquery-deparam/pull/20","diff_url":"https://github.com/AceMetrix/jquery-deparam/pull/20.diff","patch_url":"https://github.com/AceMetrix/jquery-deparam/pull/20.patch"},"body":"a new strategy (instead of #18) to resolve #17.\r\n\r\nAssume jQuery exists and try to load it, if loading it is not possible then continue but exclude any jQuery registration. I tested this out with the existing tests and they run fine when jQuery is not available (except the one test that specifically checks for jQuery registration).\r\n\r\nThe only caveat here is that AMD doesn't support defining a module with a jQuery dependency and dealing with that dependency missing (this is a limitation of AMD). The best alternative I could think of was to try and register the module into jQuery after it is defined by using a `require` statement, but this is not very elegant (really, AMD is just not designed to support this). The code would look something like this:\r\n\r\n```\r\n        define(function(){\r\n            var result = deparam(null);\r\n            require(['jquery'], function(jquery) {\r\n                $.prototype.deparam = $.deparam = result;\r\n            }, function(e) {\r\n                // jquery is missing\r\n            });\r\n            return result;\r\n        });\r\n```\r\n\r\nThis is a pretty hack-y way to do it but it does essentially accomplish the desired result. I didn't bother including this code in the PR because I'm not sure if you really want it. Easy to add another commit if you think it has value."},"comment":{"url":"https://api.github.com/repos/AceMetrix/jquery-deparam/issues/comments/166151340","html_url":"https://github.com/AceMetrix/jquery-deparam/pull/20#issuecomment-166151340","issue_url":"https://api.github.com/repos/AceMetrix/jquery-deparam/issues/20","id":166151340,"user":{"login":"patsissons","id":5505280,"avatar_url":"https://avatars.githubusercontent.com/u/5505280?v=3","gravatar_id":"","url":"https://api.github.com/users/patsissons","html_url":"https://github.com/patsissons","followers_url":"https://api.github.com/users/patsissons/followers","following_url":"https://api.github.com/users/patsissons/following{/other_user}","gists_url":"https://api.github.com/users/patsissons/gists{/gist_id}","starred_url":"https://api.github.com/users/patsissons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/patsissons/subscriptions","organizations_url":"https://api.github.com/users/patsissons/orgs","repos_url":"https://api.github.com/users/patsissons/repos","events_url":"https://api.github.com/users/patsissons/events{/privacy}","received_events_url":"https://api.github.com/users/patsissons/received_events","type":"User","site_admin":false},"created_at":"2015-12-20T20:19:52Z","updated_at":"2015-12-20T20:19:52Z","body":"so the concept that I'm playing with is that AMD won't redefine a previously defined module. So if we just attempt to fake a `jQuery` definition then it should auto-resolve for us whether it's actually available or not.\r\n\r\n```js\r\n        define('jquery', function() { return null; });\r\n        define(['jquery'], function(jquery){\r\n            return deparam(jquery);\r\n        });\r\n```\r\n\r\nI tested this out in jsfiddle and it seems to work just fine. thoughts?"}}