{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4930","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4930/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4930/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4930/events","html_url":"https://github.com/Microsoft/TypeScript/issues/4930","id":107788848,"number":4930,"title":"Feature request: static var","user":{"login":"errorx666","id":1048542,"avatar_url":"https://avatars.githubusercontent.com/u/1048542?v=3","gravatar_id":"","url":"https://api.github.com/users/errorx666","html_url":"https://github.com/errorx666","followers_url":"https://api.github.com/users/errorx666/followers","following_url":"https://api.github.com/users/errorx666/following{/other_user}","gists_url":"https://api.github.com/users/errorx666/gists{/gist_id}","starred_url":"https://api.github.com/users/errorx666/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/errorx666/subscriptions","organizations_url":"https://api.github.com/users/errorx666/orgs","repos_url":"https://api.github.com/users/errorx666/repos","events_url":"https://api.github.com/users/errorx666/events{/privacy}","received_events_url":"https://api.github.com/users/errorx666/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Runtime%20Feature","name":"Runtime Feature","color":"556677"},{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Suggestion","name":"Suggestion","color":"006b75"},{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Too%20Complex","name":"Too Complex","color":"556677"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2015-09-22T19:55:03Z","updated_at":"2015-09-28T19:38:45Z","closed_at":"2015-09-28T18:44:10Z","body":"I would like `static var` within a function to create a variable scoped outside the function which can only be accessed from within the function.  The intent is to act as a variable within the function that retains its value between invocations.\r\n\r\nAn example is below:\r\n\r\nInput:\r\n```js\r\nfunction newId() {\r\n    static var id = 0;\r\n    return id++;\r\n}\r\n```\r\n\r\nDesired compiled output:\r\n```js\r\nvar newId = ( function() {\r\n    var id = 0;\r\n    return function newId() {\r\n        return id++;\r\n    };\r\n}() );\r\n```\r\n\r\nUsage:\r\n```js\r\nnewId(); // 0\r\nnewId(); // 1\r\nnewId(); // 2\r\n```\r\n\r\nI don't believe `static let` or `static const` make sense or would be useful; `static var` should be sufficient."},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/143853232","html_url":"https://github.com/Microsoft/TypeScript/issues/4930#issuecomment-143853232","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/4930","id":143853232,"user":{"login":"GoToLoop","id":6551569,"avatar_url":"https://avatars.githubusercontent.com/u/6551569?v=3","gravatar_id":"","url":"https://api.github.com/users/GoToLoop","html_url":"https://github.com/GoToLoop","followers_url":"https://api.github.com/users/GoToLoop/followers","following_url":"https://api.github.com/users/GoToLoop/following{/other_user}","gists_url":"https://api.github.com/users/GoToLoop/gists{/gist_id}","starred_url":"https://api.github.com/users/GoToLoop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoToLoop/subscriptions","organizations_url":"https://api.github.com/users/GoToLoop/orgs","repos_url":"https://api.github.com/users/GoToLoop/repos","events_url":"https://api.github.com/users/GoToLoop/events{/privacy}","received_events_url":"https://api.github.com/users/GoToLoop/received_events","type":"User","site_admin":false},"created_at":"2015-09-28T19:38:45Z","updated_at":"2015-09-28T19:38:45Z","body":"I had no idea that would be also an old JS proposal feature.\r\nNonetheless, I still think doing it at compile time is much more efficient performance wise.\r\nAnalyzing the whole scope looking for local `static` declarations and replacing them as 1 parent closure seems a daunt job for me."}}