Section 11.8. Questions


11.8. Questions

  1. Let's say you want to create a new Number method, TRiple, which triples the current Number object's value. You also want this method available for all numbers. What are the steps you'd take?

  2. How do you hide a data member with a new object? Why would you want to?

  3. Create a function that wants a number argument and returns an error if the argument is the incorrect type. How would you implement this without having to use the return statement?

  4. We've seen object detection used previously with events:

  5.  var theEvent = nsEvent ? nsEvent : window.event;

  6. Why can't we use the same type of functionality when dealing with the opacity differences?

  7. Create a custom object with three public methodschangeState, getColor, and getStateand two private data members, background and state. Set the data members to on for state, and set a color of #fff for background color. The changeState method will test to see if the state is on, and if it is, change it to off, and the color to #000. The getColor method returns the color, and the getState returns the state.

Answers are provided in the appendix.




Learning JavaScript
Learning JavaScript, 2nd Edition
ISBN: 0596521871
EAN: 2147483647
Year: 2006
Pages: 151

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net