{"action":"created","issue":{"url":"https://api.github.com/repos/mrdoob/three.js/issues/7291","labels_url":"https://api.github.com/repos/mrdoob/three.js/issues/7291/labels{/name}","comments_url":"https://api.github.com/repos/mrdoob/three.js/issues/7291/comments","events_url":"https://api.github.com/repos/mrdoob/three.js/issues/7291/events","html_url":"https://github.com/mrdoob/three.js/issues/7291","id":109682062,"number":7291,"title":"Proposal: de-anonymize constructor names","user":{"login":"arodic","id":708984,"avatar_url":"https://avatars.githubusercontent.com/u/708984?v=3","gravatar_id":"","url":"https://api.github.com/users/arodic","html_url":"https://github.com/arodic","followers_url":"https://api.github.com/users/arodic/followers","following_url":"https://api.github.com/users/arodic/following{/other_user}","gists_url":"https://api.github.com/users/arodic/gists{/gist_id}","starred_url":"https://api.github.com/users/arodic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arodic/subscriptions","organizations_url":"https://api.github.com/users/arodic/orgs","repos_url":"https://api.github.com/users/arodic/repos","events_url":"https://api.github.com/users/arodic/events{/privacy}","received_events_url":"https://api.github.com/users/arodic/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-10-04T13:50:43Z","updated_at":"2015-10-06T16:00:43Z","closed_at":null,"body":"Since all three.js constructors are derived from anonymous functions, the constructor names are represented as empty strings. This makes it difficult to guess what \"class\" of object we are dealing with in javascript. Before [type property was added to all objects](https://github.com/mrdoob/three.js/commit/2efc87a00d5945bc9158b0474f9b5f4674ace0e3), the only way to find the class was to manually run numerous `if (x instanceof THREE.*)` checks. Type property makes this easier, but it is specific to three.js and might not work with general-purpose tools.\r\n\r\nI propose to de-anonymize the constructors by defining them like this:\r\n```\r\nTHREE.PerspectiveCamera = function PerspectiveCamera ( fov, aspect, near, far ) {\r\n```\r\nThis is a minimal change to three.js. In this case, `myPerspCamera.constructor.name` would return `\"PerspectiveCamera\"`.\r\n\r\nAlternatively, you could add a custom constructor name like this:\r\n```\r\nObject.defineProperty( THREE.PerspectiveCamera, 'name', { value: 'THREE.PerspectiveCamera' } );\r\n```\r\nIn this case, `myPerspCamera.constructor.name` would return `\"THREE.PerspectiveCamera\"`.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/mrdoob/three.js/issues/comments/145909986","html_url":"https://github.com/mrdoob/three.js/issues/7291#issuecomment-145909986","issue_url":"https://api.github.com/repos/mrdoob/three.js/issues/7291","id":145909986,"user":{"login":"mrdoob","id":97088,"avatar_url":"https://avatars.githubusercontent.com/u/97088?v=3","gravatar_id":"","url":"https://api.github.com/users/mrdoob","html_url":"https://github.com/mrdoob","followers_url":"https://api.github.com/users/mrdoob/followers","following_url":"https://api.github.com/users/mrdoob/following{/other_user}","gists_url":"https://api.github.com/users/mrdoob/gists{/gist_id}","starred_url":"https://api.github.com/users/mrdoob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrdoob/subscriptions","organizations_url":"https://api.github.com/users/mrdoob/orgs","repos_url":"https://api.github.com/users/mrdoob/repos","events_url":"https://api.github.com/users/mrdoob/events{/privacy}","received_events_url":"https://api.github.com/users/mrdoob/received_events","type":"User","site_admin":false},"created_at":"2015-10-06T16:00:43Z","updated_at":"2015-10-06T16:00:43Z","body":"Another option would be to change the code to use this pattern instead:\r\n\r\n```javascript\r\nTHREE = {};\r\n\r\nfunction Test() {\r\n}\r\n\r\nTest.prototype = {\r\n    constructor: Test\r\n};\r\n\r\nTHREE.Test = Test;\r\n```\r\n\r\nhttp://closure-compiler.appspot.com/home#code%3D%252F%252F%2520%253D%253DClosureCompiler%253D%253D%250A%252F%252F%2520%2540output_file_name%2520default.js%250A%252F%252F%2520%2540compilation_level%2520SIMPLE_OPTIMIZATIONS%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250A%250ATHREE%2520%253D%2520%257B%257D%253B%250A%250Afunction%2520Test()%2520%257B%250A%257D%250A%250ATest.prototype%2520%253D%2520%257B%250A%2520%2520%2520%2520constructor%253A%2520Test%250A%257D%253B%250A%250ATHREE.Test%2520%253D%2520Test%253B"}}