Book Image

Object-Oriented JavaScript

By : Stoyan Stefanov, Stoyan STEFANOV
Book Image

Object-Oriented JavaScript

By: Stoyan Stefanov, Stoyan STEFANOV

Overview of this book

Table of Contents (18 chapters)
Object-Oriented JavaScript
About the Author
About the Reviewers
Built-in Functions
Regular Expressions


  1. Create an object called shape that has a type property and a getType() method.

  2. Define a Triangle() constructor function whose prototype is shape. Objects created with () should have three own properties—a, b, c representing the sides of a triangle.

  3. Add a new method to the prototype called getPerimeter().

  4. Test your implementation with this code:

    	>>> var t = new Triangle(1, 2, 3);
    	>>> t.constructor

    Triangle(a, b, c)

    	>>> shape.isPrototypeOf(t)


    	>>> t.getPerimeter()


    	>>> t.getType()


  5. Loop over t showing only own properties and methods (none of the prototype's).

  6. Make this code work:

    	>>> [1,2,3,4,5,6,7,8,9].shuffle()

    [2, 4, 1, 8, 9, 6, 5, 3, 7]