Title: coffeescript and javascript handle return values in constructors differently · Issue #4 · markbates/Programming-In-CoffeeScript · GitHub
Open Graph Title: coffeescript and javascript handle return values in constructors differently · Issue #4 · markbates/Programming-In-CoffeeScript
X Title: coffeescript and javascript handle return values in constructors differently · Issue #4 · markbates/Programming-In-CoffeeScript
Description: I was once under the false impression that it didn't matter what value a constructor returned with used with new as in p = new Person() But, I've told by the gurus at the node.js and coffee-script github sites that this is not so. In gen...
Open Graph Description: I was once under the false impression that it didn't matter what value a constructor returned with used with new as in p = new Person() But, I've told by the gurus at the node.js and coffee-script ...
X Description: I was once under the false impression that it didn't matter what value a constructor returned with used with new as in p = new Person() But, I've told by the gurus at the node.js and coffee...
Opengraph URL: https://github.com/markbates/Programming-In-CoffeeScript/issues/4
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"coffeescript and javascript handle return values in constructors differently","articleBody":"I was once under the false impression that it didn't matter what value a constructor returned with used with new as in p = new Person()\n\nBut, I've told by the gurus at the node.js and coffee-script github sites that this is not so. \n\nIn general, with coffeescript it's best to use class as in: class Person ...\n\nBut, if one tries to create a function that acts as a constructor in CoffeeScript, there is at least one gotcha. The follow three short scripts demonstrate the problem, which apparently the writers of CoffeeScript and JavaScript will simply have to deal with. (The gurus who create/maintain these languages don't think its their problem and closed my bug report immediately.)\n\nSo, Mark, as someone who writes books on CoffeeScript, I hope the following might help you warn your readers. (BTW: like your book)\n\n```\n\n#-------------------------- person.coffee -----------------------------------\n\nPerson = (name) -\u003e\n @name = name\n @greet_friend = (friend) -\u003e\n console.log(\"Hello #{friend}. My name is #{@name}.\")\n ###\n wierd CoffeeScript/Node.js error:\n You will get and error if you comment the next line out\n and explicitly return the greet_friend method above.\n ###\n return null\n\n\n\nPerson.prototype.hello_world = -\u003e\n console.log(\"#{@name} says hello world.\")\n\n\np = new Person('Fred')\np.greet_friend('Mary')\np.hello_world()\n\n#------------------------- bad_person.coffee ---------------------\nPerson = (name) -\u003e\n @name = name\n @greet_friend = (friend) -\u003e\n console.log(\"Hello #{friend}. My name is #{@name}.\")\n ###\n wierd CoffeeScript v1.6.1/Node.js v0.8.22 error:\n This will bomb because we've commented out\n the 'return null' line below, which means\n that CoffeeScript will explicitly return\n the greet_friend method above.\n\n return null\n ###\n\nPerson.prototype.hello_world = -\u003e\n console.log(\"#{@name} says hello world.\")\n\n\np = new Person('Fred')\np.greet_friend('Mary')\np.hello_world()\n\n#------------------- redeemed_bad_person.js -----------------------\n\n// Generated by CoffeeScript 1.6.1 \n// but modified by me. I removed the\n// explicit return of the greet_friend\n// method.\n\n(function() {\n var Person, p;\n\n Person = function(name) {\n this.name = name;\n this.greet_friend = function(friend) {\n return console.log(\"Hello \" + friend + \". My name is \" + this.name + \".\");\n };\n /*\n wierd CoffeeScript v1.6.1/Node.js v0.8.22 error:\n This version works because we do not\n explicitly return the greet_friend \n method above.\n */\n\n };\n\n Person.prototype.hello_world = function() {\n return console.log(\"\" + this.name + \" says hello world.\");\n };\n\n p = new Person('Fred');\n\n p.greet_friend('Mary');\n\n p.hello_world();\n\n}).call(this);\n\n\n\n\n```\n","author":{"url":"https://github.com/fbeshears","@type":"Person","name":"fbeshears"},"datePublished":"2013-03-10T21:51:08.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/4/Programming-In-CoffeeScript/issues/4"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:441e116f-a9ed-89ac-aa9b-a00dbbdb983b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 95FE:41AD:116B617:172C38F:6980521E |
| html-safe-nonce | 295fc062944f286f46ed5107b9e317eace99d31424702feafe5459ef05c14659 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NUZFOjQxQUQ6MTE2QjYxNzoxNzJDMzhGOjY5ODA1MjFFIiwidmlzaXRvcl9pZCI6IjkwNTY5MzM4NzgyODcwNjE1MzQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f7e9eadd0af20c06fbeb05988535d9257f747c141a34a8e982b9254562f8ce72 |
| hovercard-subject-tag | issue:11858253 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/markbates/Programming-In-CoffeeScript/4/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3ace46a4b467641a919127e32d5fe7392b7134042d58b65e4ac28fe7139b939d/markbates/Programming-In-CoffeeScript/issues/4 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3ace46a4b467641a919127e32d5fe7392b7134042d58b65e4ac28fe7139b939d/markbates/Programming-In-CoffeeScript/issues/4 |
| og:image:alt | I was once under the false impression that it didn't matter what value a constructor returned with used with new as in p = new Person() But, I've told by the gurus at the node.js and coffee-script ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | fbeshears |
| hostname | github.com |
| expected-hostname | github.com |
| None | 60279d4097367e16897439d16d6bbe4180663db828c666eeed2656988ffe59f6 |
| turbo-cache-control | no-preview |
| go-import | github.com/markbates/Programming-In-CoffeeScript git https://github.com/markbates/Programming-In-CoffeeScript.git |
| octolytics-dimension-user_id | 3528 |
| octolytics-dimension-user_login | markbates |
| octolytics-dimension-repository_id | 2872200 |
| octolytics-dimension-repository_nwo | markbates/Programming-In-CoffeeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 2872200 |
| octolytics-dimension-repository_network_root_nwo | markbates/Programming-In-CoffeeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7c85641c598ad130c74f7bcc27f58575cac69551 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width