r/javascript • • Dec 19 '15

4 JavaScript Design Patterns You Should Know

https://scotch.io/bar-talk/4-javascript-design-patterns-you-should-know
1 Upvotes

6 comments sorted by

View all comments

4

u/[deleted] Dec 19 '15
TeslaModelS.prototype = function() {
  go: function() {
    // Rotate wheels
  },
  stop: function() {
    // Apply brake pads
  }
  return {
    pressBrakePedal: stop,
    pressGasPedal: go
  }
 }();

Surely that definition of the go and stop functions does not work like this, because it is using the go: function syntax where it should use the var go = function syntax.

EDIT:

Also

return : {
  // declare public variables and/or functions
}

return : {? Surely that is invalid syntax?