{"action":"opened","issue":{"url":"https://api.github.com/repos/somebee/imba/issues/61","labels_url":"https://api.github.com/repos/somebee/imba/issues/61/labels{/name}","comments_url":"https://api.github.com/repos/somebee/imba/issues/61/comments","events_url":"https://api.github.com/repos/somebee/imba/issues/61/events","html_url":"https://github.com/somebee/imba/issues/61","id":129458176,"number":61,"title":"Add syntax for anonymous *unbound* functions ","user":{"login":"somebee","id":8467,"avatar_url":"https://avatars.githubusercontent.com/u/8467?v=3","gravatar_id":"","url":"https://api.github.com/users/somebee","html_url":"https://github.com/somebee","followers_url":"https://api.github.com/users/somebee/followers","following_url":"https://api.github.com/users/somebee/following{/other_user}","gists_url":"https://api.github.com/users/somebee/gists{/gist_id}","starred_url":"https://api.github.com/users/somebee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/somebee/subscriptions","organizations_url":"https://api.github.com/users/somebee/orgs","repos_url":"https://api.github.com/users/somebee/repos","events_url":"https://api.github.com/users/somebee/events{/privacy}","received_events_url":"https://api.github.com/users/somebee/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-01-28T13:50:24Z","updated_at":"2016-01-28T13:50:24Z","closed_at":null,"body":"One of the nice things about Imba (imho) is the way we handle self with `do ...`, but there are still many times one would want to define regular functions *with* their own this/self scope. I'm proposing to use `func` for this, but I'm always open for other suggestions. `->` vs `=>` in CoffeeScript is nice, but it doesn't really fit in Imba. So the proposal would mean:\r\n\r\n```imba\r\nregister 'hello' do |param|\r\n    self # self refers to the outer scope\r\n    hello # implicit self is outer scope -> self.hello();\r\n\r\n# with func\r\nregister 'hello' func |param|\r\n    self # self refers to this\r\n    hello # implicit self is local scope -> this.hello();\r\n```\r\n\r\nThis might not make much sense if you're not familiar with the scoping rules in Imba, but I've received several requests/questions that would be solved with this, especially people expecting to be able to write services like they would in coffeescript:\r\n\r\n```coffee\r\nservice = {\r\n  name: \"Hello\"\r\n  start: -> true\r\n  enable: -> @start()\r\n}\r\n```\r\nIn Imba this type of pattern did not work, since the anonymous methods (start and enable) would have an implicit self referring to the context in which service is defined. But with func it would be:\r\n\r\n```imba\r\nvar service = {\r\n  name: \"Hello\"\r\n  start: func\r\n    true\r\n  enable: func\r\n    start\r\n}\r\n```\r\n"}}