Skip to content

Instantly share code, notes, and snippets.

@NatashaTheRobot
Created June 13, 2012 02:23
Show Gist options
  • Save NatashaTheRobot/2921433 to your computer and use it in GitHub Desktop.
Save NatashaTheRobot/2921433 to your computer and use it in GitHub Desktop.
Working with Javascript Hashes
<script>
var english = {
house: "A building for human habitation",
tree:"A woody perennial plant",
street: "A public road in a city or town"
};
var americanEnglish = Object.create(english, {
elevator: "A platform or compartment housed in a shaft for raising and lowering people or things to different floors or levels",
truck: "A wheeled vehicle, in particular"
})
var britishEnglish = Object.create(english);
britishEnglish.lift ="Raise to a higher position or level";
britishEnglish.lorrie ="A large, heavy motor vehicle for transporting goods or troops";
console.log(americanEnglish.elevator);
</script>
@NatashaTheRobot
Copy link
Author

Assignment: Prototypes

Make 3 "dictionary" style objects that map from words to their definitions.

  1. english: contains the definitions for the keys "house", "tree", and "street"
  2. americanEnglish: contains definitions for "elevator" and "truck". This object should use prototype delegation to include definitions from the english object
  3. britishEnglish: contains definitions for "lift" and "lorrie". This object should use prototype delegation to include definitions from the english object
  4. dynamically add a word to the english object, and make sure that it is available on the other two
    Use Object.create() to make the prototype relationships. This function does not come with JavaScript, you will need to include a copy from http://javascript.crockford.com/prototypal.html
    Do not use the keyword "new" for this exercise, except in the definition of Obect.create

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment