Cookie Consent by Free Privacy Policy Generator ๐Ÿ“Œ What the are Prototypes in JavaScript

๐Ÿ  Team IT Security News

TSecurity.de ist eine Online-Plattform, die sich auf die Bereitstellung von Informationen,alle 15 Minuten neuste Nachrichten, Bildungsressourcen und Dienstleistungen rund um das Thema IT-Sicherheit spezialisiert hat.
Ob es sich um aktuelle Nachrichten, Fachartikel, Blogbeitrรคge, Webinare, Tutorials, oder Tipps & Tricks handelt, TSecurity.de bietet seinen Nutzern einen umfassenden รœberblick รผber die wichtigsten Aspekte der IT-Sicherheit in einer sich stรคndig verรคndernden digitalen Welt.

16.12.2023 - TIP: Wer den Cookie Consent Banner akzeptiert, kann z.B. von Englisch nach Deutsch รผbersetzen, erst Englisch auswรคhlen dann wieder Deutsch!

Google Android Playstore Download Button fรผr Team IT Security



๐Ÿ“š What the are Prototypes in JavaScript


๐Ÿ’ก Newskategorie: Programmierung
๐Ÿ”— Quelle: dev.to

Prototype is one of the most confusing concepts in JavaScript to wrap your head around. even seasoned JavaScript developers still have a hard time understanding prototyping and how to apply it in their code base.

JavaScript uses Prototypes and constructors to mimic class.
But in JavaScript, we donโ€™t have classes, what we have is object. so how can we implement inheritance using objects?

Image description

Let say we have a Car object, we can define another object called Vehicle and we add all the common behavior or common method to the Vehicle object, like:

drive(startLocation, endLocation) and some how, we can link the Car object and the Vehicle object. and now we refer to Vehicle object as the prototype of the Car.

So prototype is just the parent of another object. most materials out there makes prototypes sounds complicated. so whenever you hear the word prototyping just know it is just parent.

Every object in JavaScript has a prototype or parent except for one object. objects inherits all the members define in his prototype. let see that in action.

open google chrome and go to the developer tool on the console tab, define an empty object as shown below:

Image description

you will notice a property called [[Prototype]] . you will also notice other properties like constructor, hasOwnProperty,and so on.

Every object has a constructor property which reference the function that was used to construct that object.

let see a diagrammatic representation of the x object.

Image description

so we have this x object in memory, and the x object is linked another object (lets call it the base object ). the x object inherits the properties and methods of the base object.

So every object we create in JavaScript, directly or indirectly inherits from the base object.

so the base object is the root of all object in JavaScript and so doing, it doesnโ€™t have a prototype or parent.

let say we create another object in memory called myobject.

Image description

you will observe that both x object and myobject have the same properties and methods, because they inherit from the same baseobject. and based on the fact that they are empty objects. that is, they do not have properties and methods of their own except for the the once they inherit from the baseobject.

Image description

Back in you browser developer tool, if you type in Object.getPrototypeOf(x).

Image description

what you see above is the object base with its members.
an expression like as shown below will result to true. try it out on your browser developer tool.

Object.getPrototypeOf(x) === Object.getPrototype(myobject); 
// true 

The reason is because both x and myobject has exact same prototype.

Image description

when you access the property or method of an object, JavaScript engine first look for that property on the object if it cant find it, it looks at the [[prototype]] for that object which we called base object. in JavaScript, this is what is referred to as prototypical inheritance.

Conclusion

Overall, prototypes are a powerful feature of JavaScript that allows objects to inherit properties and methods from other objects. They are very vital when one wants to create multiple objects with the same properties and methods, which makes your code DRY.

...



๐Ÿ“Œ What is prototypes and how it works in JavaScript ?


๐Ÿ“ˆ 30.65 Punkte

๐Ÿ“Œ What the are Prototypes in JavaScript


๐Ÿ“ˆ 30.65 Punkte

๐Ÿ“Œ JavaScript Object Prototypes simply explained


๐Ÿ“ˆ 30.65 Punkte

๐Ÿ“Œ Razer Prototypes Stolen from CES, Company Suspects Industrial Espionage


๐Ÿ“ˆ 23.07 Punkte

๐Ÿ“Œ Ransomware up. Breaches up. What do hackers want? Research, prototypes... all your secrets


๐Ÿ“ˆ 23.07 Punkte

๐Ÿ“Œ Intel takes to Computex 2019 with new dual-screen laptop prototypes


๐Ÿ“ˆ 23.07 Punkte

๐Ÿ“Œ Cloudera aims to fast track enterprise machine learning use cases with Applied ML Prototypes


๐Ÿ“ˆ 23.07 Punkte

๐Ÿ“Œ Google Pixel 7 and Pixel 7 Pro: Leaked prototypes suggest subtle design changes


๐Ÿ“ˆ 23.07 Punkte

๐Ÿ“Œ #63 Experiments and Prototypes ยท This Week in GNOME


๐Ÿ“ˆ 23.07 Punkte

๐Ÿ“Œ Early Fadell and Forstall iPhone Prototypes Shown in Video


๐Ÿ“ˆ 23.07 Punkte

๐Ÿ“Œ Razer Prototypes Stolen from CES, Company Suspects Industrial Espionage


๐Ÿ“ˆ 23.07 Punkte

๐Ÿ“Œ Early Fadell and Forstall iPhone Prototypes Shown in Video


๐Ÿ“ˆ 23.07 Punkte

๐Ÿ“Œ Samsung Plans to Start Production of Foldable Smartphone Prototypes in Q3


๐Ÿ“ˆ 23.07 Punkte

๐Ÿ“Œ Samsung Galaxy S8+ Prototypes Show Dual-Camera Setup on the Back


๐Ÿ“ˆ 23.07 Punkte

๐Ÿ“Œ Apple preps pair of super-thin folding iPhone prototypes


๐Ÿ“ˆ 23.07 Punkte

๐Ÿ“Œ Original iPhone Prototypes Called Wallabies Revealed


๐Ÿ“ˆ 23.07 Punkte

๐Ÿ“Œ Surface Phone Hardware Ready, Prototypes Now Being Tested - Report


๐Ÿ“ˆ 23.07 Punkte

๐Ÿ“Œ instagram prototypes handing your location history to facebook


๐Ÿ“ˆ 23.07 Punkte

๐Ÿ“Œ Microsoft Research Publishes Prototypes For Phones and Tablets Gaming Controllers


๐Ÿ“ˆ 23.07 Punkte

๐Ÿ“Œ Microsoft prototypes Xbox controllers for phones and tablets (update)


๐Ÿ“ˆ 23.07 Punkte

๐Ÿ“Œ Microsoft Research prototypes modular mobile Xbox controller on video


๐Ÿ“ˆ 23.07 Punkte

๐Ÿ“Œ Apple Partners Start Building Foldable iPhone Prototypes


๐Ÿ“ˆ 23.07 Punkte

๐Ÿ“Œ Lian Li shows off four PC case prototypes at its 2021 digital expo


๐Ÿ“ˆ 23.07 Punkte

๐Ÿ“Œ Preservation Effort Unearths Over 750 PlayStation 2 Game Prototypes


๐Ÿ“ˆ 23.07 Punkte

๐Ÿ“Œ Pencil 3.1.1 - Easily create prototypes and mockups.


๐Ÿ“ˆ 23.07 Punkte

๐Ÿ“Œ Apple is working on at least two folding iPhone prototypes


๐Ÿ“ˆ 23.07 Punkte

๐Ÿ“Œ V8 Internals for JavaScript Developers (Make Your JavaScript Faster)


๐Ÿ“ˆ 15.16 Punkte

๐Ÿ“Œ JavaScript: Dirty Parts of the Language (aka Maneuvering JavaScript Errors)


๐Ÿ“ˆ 15.16 Punkte

๐Ÿ“Œ JavaScript: Dirty Parts of the Language (aka Maneuvering JavaScript Errors)


๐Ÿ“ˆ 15.16 Punkte

๐Ÿ“Œ A Brief History of JavaScript by the Creator of JavaScript


๐Ÿ“ˆ 15.16 Punkte

๐Ÿ“Œ Why Is JavaScript So Fast? (aka JavaScript Engines - How Do They Even?)


๐Ÿ“ˆ 15.16 Punkte

๐Ÿ“Œ Dynamic Rendering for JavaScript web apps - JavaScript SEO


๐Ÿ“ˆ 15.16 Punkte

๐Ÿ“Œ Top 10 JavaScript Vulnerabilities (aka OWASP Top 10 for JavaScript Developers)


๐Ÿ“ˆ 15.16 Punkte

๐Ÿ“Œ Javascript: Neue Facebook-Webseite setzt komplett auf Javascript


๐Ÿ“ˆ 15.16 Punkte











matomo