Can anyone recommend any decent sources, books, courses, links etc to learn about object composition.
Something with real world examples that go beyond cats ‘meowing’ and dogs ‘barking’.
Thanks:)
Can anyone recommend any decent sources, books, courses, links etc to learn about object composition.
Something with real world examples that go beyond cats ‘meowing’ and dogs ‘barking’.
Thanks:)
Typically object oriented programming is not as good a fit for JavaScript as other techniques. JavaScript can do it, but it’s designed to be more effective when other techniques are used instead.
I presume you are referring to ‘functional’ programming? If so that’s great — As well as other sources, I am currently following Kyle Simpsons video course on the topic.
I would still like to know more about object composition in practice though. Just ruling it out, without looking into it myself, seems a bit ‘blinkered’ to me.
Well the following book comes well recommended from 2016
https://www.amazon.com/Mastering-JavaScript-Object-Oriented-Programming-Chiarelli/dp/1785889109
Next before that from 2013
And lastly from 2008
https://www.goodreads.com/book/show/4355468-object-oriented-javascript
Stoyan Stefanov’s books are great, I have copy of Design Patterns and have read through a lot of the 2008 copy of Object-Orientated Javascript — albeit a long time ago. Not sure he covers ‘object composition’ though.
Mastering JavaScript Object-Oriented Programming, look interesting. I may well have to open up my Packt subscription again:)
Thanks Paul.
Hi @rpg_digital, I’d just like to add that object composition is not necessarily about OOP in the classical sense; it also works very well with just object literals and factory functions, even following a more functional paradigm. In fact Eric Elliot, a rather enthusiastic opponent of OOP in JS, has written quite a bit on this topic – e.g. here and here (although his writings should be taken with a grain of salt).
Hi m3g4p0p, that is exactly what I was referring to, I guess I should have put an example up.
e.g.
function Dog (name) {
dog = {
name
}
return Object.assign(
{},
barking(dog)
)
}
const barking = (state) => ({
bark () {
return `${state.name} barks. Woof!!`
}
})
As I say most of these examples seem to be limited to domestic pets and their activities:)
Trying to work out whether my real world application should be barking or quacking is another matter. (jest)
Thanks for the Eric Elliot links, and also the heads up. That is much appreciated.
Hehe, well here’s one with sweets for a change… :-)
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.