0
[Solved] Can anyone explain me the following terms used in JS and give examples?
Object Method Function Difference between while and do...while loop
6 Réponses
+ 2
part 1/2
Simen unlike most of OOP languages, JS is an OOP language based on prototypes rather than on classes... even if 'class' keyword was later added as syntactic sugar ^^
this make JS object work slighly differently of classical 'class' inheritance objects by using 'prototypal' inheritance objects...
that doesn't means JS object are not instances, only that the way they are is not exactly the same than from class-based OOP... even when using a JS 'class' constructor (under the hood they are still prototype-based objects)
in fact, an object declared literally (var myobject = { /* properties and/or methods or nothing */ };) is an instance of the base Object constructor (implicitly, equivalent to: var myobject = new Object(); /* then attaching zero to many properties / methods to the new instance created */)
[ end of part 1/2 ] (to be continued in next post...)
+ 2
part 2/2
you could dive into 2nd link suggested by Martin Taylor specially by visiting links provided at that page (under "Guides" section) such as https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object-oriented_JS ("Object-oriented JavaScript for beginners") as well as previous "Object basics" introduction or next "Object prototypes" & "Inheritance in Javascript"
'class' syntactic sugar is even a simpler (specially when need to inherit another constructor) way to define constructors, but you must understand how objects and prototypes really works to got all their power and flexibility (as some downsides: nothing is all good or all bad) ;)
as deeper dive into I recommend to read (free) "You don't know JS" book series, and specifically the title "this & Object prototypes":
https://github.com/getify/You-Dont-Know-JS/blob/1st-ed/this%20&%20object%20prototypes/README.md#you-dont-know-js-this--object-prototypes
1st ed. summary: https://github.com/getify/You-Dont-Know-JS/blob/1st-ed/README.md
+ 1
https://developer.mozilla.org/en-US/
visit this site and search for anything related to JS, you will find an answer with very good examples.
+ 1
Martin Taylor I know what they do but I don't know where to use them in real life.
+ 1
Martin Taylor Thanks for the feedback. I am not very familiar with JavaScript myself, so I appreciate the feedback!
0
Just practice a lot. You will eventually get to know where to use them.