{"action":"created","issue":{"url":"https://api.github.com/repos/haroldiedema/joii/issues/28","repository_url":"https://api.github.com/repos/haroldiedema/joii","labels_url":"https://api.github.com/repos/haroldiedema/joii/issues/28/labels{/name}","comments_url":"https://api.github.com/repos/haroldiedema/joii/issues/28/comments","events_url":"https://api.github.com/repos/haroldiedema/joii/issues/28/events","html_url":"https://github.com/haroldiedema/joii/pull/28","id":188569391,"number":28,"title":"Feature Addition: Static members","user":{"login":"cjmanca","id":6020593,"avatar_url":"https://avatars.githubusercontent.com/u/6020593?v=3","gravatar_id":"","url":"https://api.github.com/users/cjmanca","html_url":"https://github.com/cjmanca","followers_url":"https://api.github.com/users/cjmanca/followers","following_url":"https://api.github.com/users/cjmanca/following{/other_user}","gists_url":"https://api.github.com/users/cjmanca/gists{/gist_id}","starred_url":"https://api.github.com/users/cjmanca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cjmanca/subscriptions","organizations_url":"https://api.github.com/users/cjmanca/orgs","repos_url":"https://api.github.com/users/cjmanca/repos","events_url":"https://api.github.com/users/cjmanca/events{/privacy}","received_events_url":"https://api.github.com/users/cjmanca/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-10T17:25:37Z","updated_at":"2016-11-11T10:51:51Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/haroldiedema/joii/pulls/28","html_url":"https://github.com/haroldiedema/joii/pull/28","diff_url":"https://github.com/haroldiedema/joii/pull/28.diff","patch_url":"https://github.com/haroldiedema/joii/pull/28.patch"},"body":"Can now specify \"static\" for functions and properties, to have them be\r\nattached to the class it's self, rather than it's instances. \r\n\r\nDoes NOT break backwards compatibility.\r\n\r\nNot ready to be merged, but wanted to get things started. Seems to be working correctly, but limited unit tests so far. Would appreciate help thinking of more unit tests.\r\n\r\nTwo ways to access the inner (private/protected) static scope:\r\n\r\n```javascript\r\nvar MyClass = JOII.ClassBuilder('MyClass', {}, function (MyClass) { return { \r\n    'private static number num' : 1,\r\n    'public static string str' : 'Works!',\r\n    'public test()' : function() {\r\n        MyClass.num = 2; // uses the variable passed to this function\r\n        this.getStatic().num = 3; // uses the getStatic() private method to retrieve access to the inner static scope\r\n    }\r\n}});\r\nMyClass.getStr(); // returns 'Works!'\r\n```"},"comment":{"url":"https://api.github.com/repos/haroldiedema/joii/issues/comments/259932376","html_url":"https://github.com/haroldiedema/joii/pull/28#issuecomment-259932376","issue_url":"https://api.github.com/repos/haroldiedema/joii/issues/28","id":259932376,"user":{"login":"haroldiedema","id":567518,"avatar_url":"https://avatars.githubusercontent.com/u/567518?v=3","gravatar_id":"","url":"https://api.github.com/users/haroldiedema","html_url":"https://github.com/haroldiedema","followers_url":"https://api.github.com/users/haroldiedema/followers","following_url":"https://api.github.com/users/haroldiedema/following{/other_user}","gists_url":"https://api.github.com/users/haroldiedema/gists{/gist_id}","starred_url":"https://api.github.com/users/haroldiedema/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haroldiedema/subscriptions","organizations_url":"https://api.github.com/users/haroldiedema/orgs","repos_url":"https://api.github.com/users/haroldiedema/repos","events_url":"https://api.github.com/users/haroldiedema/events{/privacy}","received_events_url":"https://api.github.com/users/haroldiedema/received_events","type":"User","site_admin":false},"created_at":"2016-11-11T10:51:51Z","updated_at":"2016-11-11T10:51:51Z","body":"Hmm....\r\n\r\nI don't like the way the developer has to use `getStatic()` to get to the static-scope.\r\nSince objects can be referenced, why not just call it `static`?\r\n\r\nI'd rather do this:\r\n```javascript\r\nvar MyClass = Class({\r\n    'public static number foobar': 42,\r\n\r\n    construct: function () {\r\n        this.static.foobar = 50;\r\n    }\r\n});\r\n\r\nconsole.log(MyClass.foobar); // This _should_ work and return 42.\r\n\r\nnew MyClass();\r\n\r\nconsole.log(MyClass.foobar); // This _should_ work and return 50;\r\n```\r\nSince scalar values can't be used as pointers/references, I ran into this problem myself a long time ago. Hence I decided not to implement it. The way it can be achieved is indeed to use some sort of scope (object), but the way people had to use it wasn't something I liked - at all. There's also a performance impact since you have to re-bind an object to the correct scope everytime you instantiate a class, while this _should_ only happen when you declare a class.\r\n\r\nI would love to see a correct implementation for this, but I think there are more cons to this than pros :disappointed: \r\n\r\nRight now, using the \"const\" property type does somewhat what you'd expect it to do.\r\n```javascript\r\nvar MyClass = Class({\r\n    'const foobar': 42\r\n});\r\n\r\nconsole.log(MyClass.foobar); // 42.\r\n```\r\nThe only problem with this approach is that even though the property is declared as `const`, it can still be modified. I haven't found a way to protect these properties from being modified. This means that effectively, the variable is a static, as long as it's called from the class declaration rather than an instantiated object:\r\n\r\n```javascript\r\nvar mc = new MyClass();\r\n\r\nconsole.log(MyClass.foobar); // 42\r\nconsole.log(mc.foobar); // undefined\r\n```\r\n"}}
{"actor":{"display_login":"haroldiedema"}}