Webmaster Forum Rules | Posting Guide | Contact Us | Testimonials | Contributing Geek Program | Advertise on Geek/Talk
Welcome to the GeekTalk Webmaster Discussion Forums from GeekVillage.com

Click Here To Register. It's Free!

Go Back   geek/talk: Web publishing business discussion > YOUR CREATION: Building & Maintaining A Web Site > Web Development - Programming / Coding
User Name
Register FAQ Calendar Search Today's Posts Mark Forums Read

Thread Tools Search this Thread Display Modes
Old 03-17-2017, 05:58 AM   #1
Registered User
Join Date: Jun 2015
Posts: 246
Default Prototype paradigm

This paradigm makes use of an object’s prototype property, which is considered to be the prototype upon which new objects of that type are created. Here, an empty constructor is used only to set up the name of the class. Then, all properties and methods are assigned directly to the prototype property. Rewriting the previous example, the code looks like this:

function Car() {
Car.prototype.color = “red”;
Car.prototype.doors = 4;
Car.prototype.mpg = 23;
Car.prototype.showColor = function () {
var oCar1 = new Car();
var oCar2 = new Car();
In this code, the constructor (Car) is defined first and contains no code. The next few lines of code define the object’s properties by adding them to the prototype property of Car. When new Car() is called, all the properties of prototype are immediately assigned to the object that was created, meaning that all instances of Car contain pointers to the same showColor() function. Semantically, everything looks like it belongs to an object, so the two problems of the previous paradigms have been solved. As an added bonus, this method allows the use of the instanceof operator to check what kind of object a given variable points to. So the following line outputs true:

Fat Cutter | Hot Shaper | Asthijivak
beingchinmay is offline   Reply With Quote


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
New Netscape Navigator Beta Larwee Web Design and Webmaster Issues 1 11-30-2004 09:02 PM

Please support our advertisers. They ensure our survival.

All times are GMT -5. The time now is 07:01 PM.

GeekVillage.com is copyright © 1998-2015 Curiosity Cave - Science gifts for clever kids. All rights reserved.
Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.