{"action":"created","issue":{"url":"https://api.github.com/repos/hprose/hprose-js/issues/4","labels_url":"https://api.github.com/repos/hprose/hprose-js/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/hprose/hprose-js/issues/4/comments","events_url":"https://api.github.com/repos/hprose/hprose-js/issues/4/events","html_url":"https://github.com/hprose/hprose-js/issues/4","id":72740555,"number":4,"title":"Make hprose aware of CommonJS","user":{"login":"IngwiePhoenix","id":2893716,"avatar_url":"https://avatars.githubusercontent.com/u/2893716?v=3","gravatar_id":"","url":"https://api.github.com/users/IngwiePhoenix","html_url":"https://github.com/IngwiePhoenix","followers_url":"https://api.github.com/users/IngwiePhoenix/followers","following_url":"https://api.github.com/users/IngwiePhoenix/following{/other_user}","gists_url":"https://api.github.com/users/IngwiePhoenix/gists{/gist_id}","starred_url":"https://api.github.com/users/IngwiePhoenix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IngwiePhoenix/subscriptions","organizations_url":"https://api.github.com/users/IngwiePhoenix/orgs","repos_url":"https://api.github.com/users/IngwiePhoenix/repos","events_url":"https://api.github.com/users/IngwiePhoenix/events{/privacy}","received_events_url":"https://api.github.com/users/IngwiePhoenix/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-05-03T03:34:12Z","updated_at":"2015-05-04T00:02:08Z","closed_at":null,"body":"I am planning on writing an RPC layer that is capable of running on \"almost\" all frameworks. In order to properly support this, hprose-js needs to learn to export. This is simple. As you know NodeJS, this will look very familiar to you:\r\n\r\n```javascript\r\nmodule.exports = hprose;\r\n```\r\n\r\nThe idea is, to have hprose initialize on a local variable first (`hprose` in my case). Then we can do something like jQuery does here: https://github.com/jquery/jquery/blob/2.1.4/dist/jquery.js#L15-L38\r\n\r\nDo you think this is possible?\r\n\r\nKind regards,\r\nIngwie"},"comment":{"url":"https://api.github.com/repos/hprose/hprose-js/issues/comments/98558220","html_url":"https://github.com/hprose/hprose-js/issues/4#issuecomment-98558220","issue_url":"https://api.github.com/repos/hprose/hprose-js/issues/4","id":98558220,"user":{"login":"IngwiePhoenix","id":2893716,"avatar_url":"https://avatars.githubusercontent.com/u/2893716?v=3","gravatar_id":"","url":"https://api.github.com/users/IngwiePhoenix","html_url":"https://github.com/IngwiePhoenix","followers_url":"https://api.github.com/users/IngwiePhoenix/followers","following_url":"https://api.github.com/users/IngwiePhoenix/following{/other_user}","gists_url":"https://api.github.com/users/IngwiePhoenix/gists{/gist_id}","starred_url":"https://api.github.com/users/IngwiePhoenix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IngwiePhoenix/subscriptions","organizations_url":"https://api.github.com/users/IngwiePhoenix/orgs","repos_url":"https://api.github.com/users/IngwiePhoenix/repos","events_url":"https://api.github.com/users/IngwiePhoenix/events{/privacy}","received_events_url":"https://api.github.com/users/IngwiePhoenix/received_events","type":"User","site_admin":false},"created_at":"2015-05-04T00:02:08Z","updated_at":"2015-05-04T00:02:08Z","body":"RequireJS - which basically is CommonJS - is becoming very, very popular these days. In fact, jQuery, for instance, handles both styles, AMD and CommonJS at once, and allows to be ran inside NodeJS if a `window-like object can be specified`, so they say.\r\n\r\nWhat I would suggest for hprose-js is that it implements at least CommonJS. It gives developers the option to smoothly move their code to another platform without losing much features or having a big burden of converting their code.\r\n\r\nActually I don't know what the difference between hprose-js and hprose-html5 is. It looks very similar from a short glance.\r\n\r\nSo my opinion is, that you should add RequireJS support, since that is pretty much CommonJS.\r\n\r\nHere is a little template that can maybe help you with getting this going:\r\n\r\n```javascript\r\n(function(root, construct){\r\n    if(typeof module != \"undefined\" && typeof exports == \"object\") {\r\n        module.exports = construct();\r\n    } else {\r\n        root.hprose = construct();\r\n    }\r\n})(this, function(){\r\n    \r\n    // hprose code goes here. Here is an example:\r\n    var hprose = {};\r\n    hprose.foo = function() {}\r\n    \r\n    return hprose;\r\n    // A module that require()'d this file now gets the hprose object.\r\n    \r\n});\r\n```\r\n\r\nKind regards, Ingwie."}}