Example Of Creating Objects

CK CK 3788 
Created at  
403 0 0
an example of creating object in javascript,
taken from
http://www.wdvl.com/Authoring/JavaScript/Tutorial/objects.html

direct instance of an object

Despite the awkward sound name, a "direct instance of an object" simply means creating a new single object, such as myPetDog:


myPetDog=new Object();
 myPetDog.name="Barney";
 myPetDog.breed="beagle";
 myPetDog.year=1981;

 

Assigning a method to your new object is also simple. Assume that you already have coded a function named woof(), which causes a barking sound to play:


myPetDog.woof=woof;

 

prototype of an object
Sometimes, you'll want to create a "template" or prototype of an object. This does not create an actual instance of the object, but defines the structure of the object. In the future, then, you can quickly stamp out a particular instance of the object. Suppose that instead of myPetDog, you created a prototype object named petDog. This object could then be a template for a particular pet dog object. First, create a function which defines the petDog structure:

function petDog(name, breed, year)
{
  this.name = name;
  this.breed = breed;
  this.year = year;
}

 

Now that the petDog prototype has been set, you can quickly create single instances of a new object based on the petDog structure:


myPetDog=new petDog("barney","beagle",1981);
yourPetDog=new petDog("max","terrier",1990);

Tags HTML Javascript Object new Facebook X
Comments 0
Similar posts
  1. Printing A Page
    378
  2. Linking Drop Downs
    576
  3. Roman Numerals From Integers
    511
  4. Get A Print Dialog Box By Clicking A Button
    818
  5. Keyboard event detection (Key Tracker)
    1,087
  6. IsIn For Arrays
    568
  7. Cross Browser Event Management Functions Using JavaScript
    611
  8. Javascript & Cookie based Visitor Application
    435
  9. How to record visitor's name by Cookie
    411
  10. Save And Restore Form Cookies in Javascript
    334
  11. Let popup once for event dialog or something like that in Javascript
    425
  12. New content notifier in Javascript
    597
  13. Cookie Redirect
    496
  14. Cookie enabled browser checking in Javascript
    342
  15. Access Granted
    586
  16. Greeting For The Time Of Day
    393
  17. Displays the number of pages that the users browser has displayed in its session
    666
  18. Address Book
    576
  19. Basic Date Display
    511
  20. Javascript implemented Calendar
    421
  21. Javascript based Alarm Clock
    666
  22. How to get date time in Javascript ?
    498
  23. Hiding HTML on the browser
    461
  24. Getting WebSearchers On Your Site
    373
  25. Javascript Mouse Event Handler Example
    403
  26. Select And Deselect All Checkboxes By Javascript
    632
  27. Confirm The Link Clicked
    630
  28. Enlarge Image
    514
  29. Dual Scroller
    332
  30. Cursor Changer
    383
  1. Javascript implemented Calendar
    421
  2. Basic Date Display
    511
  3. Address Book
    576
  4. Displays the number of pages that the users browser has displayed in its session
    666
  5. Greeting For The Time Of Day
    393
  6. Access Granted
    586
  7. Cookie enabled browser checking in Javascript
    342
  8. Cookie Redirect
    496
  9. New content notifier in Javascript
    597
  10. Let popup once for event dialog or something like that in Javascript
    425
  11. Save And Restore Form Cookies in Javascript
    334
  12. How to record visitor's name by Cookie
    411
  13. Javascript & Cookie based Visitor Application
    435
  14. Cross Browser Event Management Functions Using JavaScript
    611
  15. Printing A Page
    378
  16. Linking Drop Downs
    576
  17. Roman Numerals From Integers
    511
  18. Get A Print Dialog Box By Clicking A Button
    818
  19. Keyboard event detection (Key Tracker)
    1,087
  20. IsIn For Arrays
    568
Recently updated
  1. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    40
  2. Why SPF and DKIM Are Essential for Linux Email Servers?
    34
  3. How do I create animated background for Google Meet?
    20,611
  4. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    244
  5. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    94
  6. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    157
  7. Array of arguments passed to script in PHP
    90
  8. Invalid Auction Storms in Ad Tech
    98
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    202
  10. The Two Clocks of Ad Server Architecture
    70
  11. Frequency Cap Architecture Overview
    514
  12. Collecting Proof-of-Play from 100,000 Screens
    146
  13. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    287
  14. What is RedisVL?
    109
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    230
  16. TPU & GPU Cluster Management Tools
    243
  17. The Concept of Scaffolding in AI Agents
    233
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    583
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    258
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    339
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    202
  22. Machine Learning: Training vs. Ranking
    221
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    222
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    195
  25. Designing a Data Curation System Around a Vector Database
    220
  26. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    256
  27. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    656
  28. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    195
  29. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    217
  30. Understanding Data Lineage
    260