Skip to Content
JavaScript : Object-Oriented Programming
book

JavaScript : Object-Oriented Programming

by Kumar Chetan Sharma et al
August 2016
Beginner to intermediate
847 pages
17h 28m
English
Packt Publishing
Content preview from JavaScript : Object-Oriented Programming

Exercises

  1. Look at this code:
    function F() {
      function C() {
        return this;
      }
      return C();
    }
    var o = new F();

    Does the value of this refer to the global object or the object o?

  2. What's the result of executing this piece of code?
    function C(){ 
      this.a = 1;
      return false;
    }
    console.log(typeof new C());
  3. What's the result of executing the following piece of code?
    > c = [1, 2, [1, 2]];
    > c.sort();
    > c.join('--'); 
    > console.log(c); 
  4. Imagine the String() constructor didn't exist. Create a constructor function, MyString(), that acts like String() as closely as possible. You're not allowed to use any built-in string methods or properties, and remember that String() doesn't exist. You can use this code to test your constructor:
    > var s = new MyString('hello'); > s.length; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

JavaScript: Functional Programming for JavaScript Developers

JavaScript: Functional Programming for JavaScript Developers

Ved Antani, Simon Timms, Dan Mantyla
Mastering JavaScript Object-Oriented Programming

Mastering JavaScript Object-Oriented Programming

Andrea Chiarelli, Lyubomyr Rudko

Publisher Resources

ISBN: 9781787123595Supplemental Content