Objects Flashcards
(14 cards)
What is a method in javascript
Methods are properties that contain a Function() object.
Give a constructor example
var Person = function(living,age,gender){ this.living = living; ... } var Cody = new Person(true,33,male);
What is the Object() object
An empty generic object container
What are the two methods of object creation
1) via a custom constructor var Car = function Car(color); var redCar = new Car('red'); 2) Via the Object() constructor: var redCar = new Object(); redCar.colorc = 'red';
Explain the ‘new’ keyword
When using new, javascript sets the value of ‘this’ to the newly constructed object. And the new object will be returned by default instead of ‘false’.
What are the nine native (global) object constructors
Number(), String(), Boolean(), Object(), Array(),Function(), Date(), RegExp(), Error()
What are literals
Shortcuts for manufacturing most of the native object values without having to use new Foo() or new Bar(). E.g. var myNumber = new Number(23); var myNumberLiteral = 23;
var myObject = new Object(); var myObjectLiteral = {};
Give an example of a function literal
var myFunction = new Function("x","y","return x*y"); var myFunctionLiteral = function(x,y) {return x*y}
Give an example of an array literal
var myArray = new Array('foo','bar'); var myArrayLiteral = ['foo','bar'];
What are primitive values?
Values that are simple, irreducible, not made up of other values.
How are primitive values stored/copied?
the value is literally copied/stored.
How are complex values stored/copied?
by reference.
How do you refer to the constructor of an object?
All objects have a constructor property
How do you know if an object is an instance of a constructor function?
by using the instanceof keyword