• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

In JS We Trust

trung tâm giáo dục thường xuyên javascript: youtube.com/hoccoban

  • giới thiệu
  • js cơ bản
  • bài tập
  • interview
  • tài nguyên

testing object and prototype

by Vuong Nguyen
January 15, 2019December 30, 2019Filed under:
  • bài tập

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

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

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

4. Test your implementation with the following code:

var t = new Triangle(1, 2, 3);
t.constructor === Triangle; //true
shape.isPrototypeOf(t); //true
t.getPerimeter(); //6
t.getType(); //"triangle"

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

6. Make the following code work:

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

Nguồn: Object-oriented JavaScript (S.Stefanov, page 170)

Post navigation

Previous Post 6 ways to create object in JavaScript
Next Post 6 ways to avoid callback hell

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Bài viết mới

  • Server lưu JWT là một sai lầm, tại sao lại như thế?
  • 6 ways to avoid callback hell
  • testing object and prototype
  • 6 ways to create object in JavaScript
  • Kế thừa Prototype ngang và dọc

Chuyên mục

  • bài tập
  • js cơ bản
  • tips
  • web

Comments

  • admin on Kế thừa Prototype ngang và dọc
  • Nguyen Van Tu on Kế thừa Prototype ngang và dọc
  • admin on Kế thừa Prototype ngang và dọc
  • admin on Kế thừa Prototype ngang và dọc
  • admin on Kế thừa Prototype ngang và dọc

Copyright © 2021 · Milan Pro on Genesis Framework · WordPress · Log in