4 ms·
> I code a lot of web stuff but the only time > I've used OOP in JS is when I make games That's very doubtful. Ever used a String in JavaScript? Ever used
by jashkenas 13y ago
> I code a lot of web stuff but the only time
> I've used OOP in JS is when I make games
That's very doubtful. Ever used a String in JavaScript? Ever used an Array? Ever used a regular expression? How about a function? All of those things are objects in JavaScript — and are used and useful as such.
The notion that OOP === single-inheritance needs to be put out of its misery. An object is anything that binds together data and code in a single value, and you use them all the time.
- scotty79 13y agoI think he meant implementing at least two of his own objects where one inherits from the other.
- dustingetz 13y agoYour first paragraph is true of functional languages too, which are decidedly not OO by any modern definition. OOP is about inheritance and encapsulating mutable state.
- e12e 13y agoAn object is by definition data with associated functions to operate on that data. One might say that functional programming couples functions(methods) with data, while object oriented programs couple data with methods(functions). In an object oriented paradigm, you send messages between objects, in a functional paradigm you pass data to functions. But, functions can normally take functions as arguments as well -- and all in all you can do one thing in the other -- but I think the big difference is on whether you model "smart data" or operations/functions. Classes comes in when you have many objects that share behaviour. That can be modelled as traits/interfaces or as classes (grouping methods, and possibly singleton state). These things can be inherited, or assigned (as in javascript/self).