{"action":"created","issue":{"url":"https://api.github.com/repos/musictheory/oj/issues/81","labels_url":"https://api.github.com/repos/musictheory/oj/issues/81/labels{/name}","comments_url":"https://api.github.com/repos/musictheory/oj/issues/81/comments","events_url":"https://api.github.com/repos/musictheory/oj/issues/81/events","html_url":"https://github.com/musictheory/oj/issues/81","id":118997069,"number":81,"title":"Question regarding runtime","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":3,"created_at":"2015-11-26T08:36:44Z","updated_at":"2015-11-26T10:15:59Z","closed_at":null,"body":"As of current, all classes, protocols and alike are stored inside the runtime's `$oj_oj` global variable. I'd like to ask something about it.\r\n\r\nWhen generating the code, the original variable ends up with no result:\r\n\r\n```javascript\r\nvar Foo = $oj_oj._registerClass({ $oj_c_Foo:1 }, null, function($oj_s, $oj_m) { function Foo() { this.constructor = Foo;this.$oj_id = ++$oj_oj._id;}\r\n$oj_s.$oj_f_greet = function() { console.log(\"Hi\"); }\r\nreturn Foo;});\r\n```\r\n\r\nIn this case, `Foo` ends up as an empty variable.\r\n\r\nMy questions:\r\n\r\n- Why are we actually writing into a global variable instead of filling a variable that we already have? Is it to support inheritance or..?\r\n- The empty variables usually stick around till their scope ends. Why are they even generated/left behind, if we write into a global anyway?\r\n- What are the advantages of using the global variable compared to just using local variables?\r\n\r\nKind regards, Ingwie"},"comment":{"url":"https://api.github.com/repos/musictheory/oj/issues/comments/159868048","html_url":"https://github.com/musictheory/oj/issues/81#issuecomment-159868048","issue_url":"https://api.github.com/repos/musictheory/oj/issues/81","id":159868048,"user":{"login":"iccir","id":1097294,"avatar_url":"https://avatars.githubusercontent.com/u/1097294?v=3","gravatar_id":"","url":"https://api.github.com/users/iccir","html_url":"https://github.com/iccir","followers_url":"https://api.github.com/users/iccir/followers","following_url":"https://api.github.com/users/iccir/following{/other_user}","gists_url":"https://api.github.com/users/iccir/gists{/gist_id}","starred_url":"https://api.github.com/users/iccir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iccir/subscriptions","organizations_url":"https://api.github.com/users/iccir/orgs","repos_url":"https://api.github.com/users/iccir/repos","events_url":"https://api.github.com/users/iccir/events{/privacy}","received_events_url":"https://api.github.com/users/iccir/received_events","type":"User","site_admin":false},"created_at":"2015-11-26T10:15:59Z","updated_at":"2015-11-26T10:15:59Z","body":"`oj.class_getName(Foo)` currently works inside of the Foo class, as the constructor is named `Foo`, that's a bug though!"}}