Jump to content

Functions in object's prototype? Benefits?


jjcale
 Share

Recommended Posts

Hi,

I have seen two approaches to encapsulate Phaser functions into objects:

1)

in a state object directly

2)

in a state object's prototype

What are the benefits of each approach? I assume that I would create only one instance of the state object, so there is little memory overhead (created instance + class object itself). I have no plans for inheritance.

Thanks,

JJ

 

Link to comment
Share on other sites

Although in this case it probably makes very little difference as an app gets complex you're hitting on a very contentious issue in JS currently regarding class syntax, hierarchies, prototypal inheritance and object linking.

This is a nice gist showing object linking (which is actually all JS has, the es2015 class syntax is a big fat red herring and will always be so in a dynamic language).

The biggest writer in this field is Kyle Simpson (@getify), who wrote the You Dont Know JS books, but it touches on Crockford's opinions, how Brendan Eich thought JS should evolve and Eric Elliott is a big proponent of shunning classical-shims for JS 'inheritance'.

Some more info:

http://akonwi.io/blog/oloo (this is a very brief rehash of Kyle Simpson's stuff, I'd recommend getting the YDKJS books for more info, or trawl through his blog, most of the book content is covered there in one way or another)

https://medium.com/javascript-scene/10-interview-questions-every-javascript-developer-should-know-6fa6bdf5ad95#.h9vtxj7e5 this shows how important Eric Elliott believes structure to be by only hiring people who understand it! There are also a raft of great links to other articles on the subject in there.

https://medium.com/@cscalfani/goodbye-object-oriented-programming-a59cda4c0e53#.6ubbgc641

Quote

"Favour object composition over class inheritance" GOF

 

Quote

  "The problem with object-oriented languages is they’ve got all this implicit environment that they carry around with them. You wanted a banana but what you got was a gorilla holding the banana and the entire jungle." Joe Armstrong

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...