/**
* OOP: ch.3 - Understanding Objects
* =====================================================
* Keep in mind that objects in JavaScript
* are dynamic, meaning that they can change at any
* point during code execution. A large part of
* JavaScript programming is managing those objects,
* which is why understanding how objects work is
* key to understanding JavaScript as a whole
*/
/*
* Defining Properties:
* =====================
* Object constructor and object literal
*/
//literal
var person1 = {
firstName: "Makayla"
};
// object Object constructor
var person2 = new Object();
/**
* When a property is first added to an object,
* JavaScript uses an internal method called [[Put]]
* on the object. The [[Put]] method creates a spot
* in the object to store the property. You can
* compare this to adding a key to a hash table
* for the first time. This operation specifies
* not just the initial value, but also some
* attributes of the property.
*
* The result of calling [[Put]] is the creation
* of an own property on the object. An own
* property simply indicates that the specific
* instance of the object owns that property.
* The property is stored directly on the instance,
* and all operations on the property must be
* performed through that object.
*
* NOTE: ownProperty !== prototype property
*/
//props for each
person1.age = "Redacted";
person2.firstName = "Katie";
person2.age = "Redacted";
console.log('person1 => ', person1); //Makayla
console.log('person2 => ', person2); //Katie
//test ownProperty
for( var prop in person1){
if( person1.hasOwnProperty(prop) ){
console.log(prop);
}
}
//update person names
var t = setTimeout(function(){
/**
* When a new value is assigned to an
* existing property, a separate operation
* called [[Set]] takes place. This
* operation replaces the current value
* of the property with the new one.
*/
person1.firstName = "Greg";
person2.firstName =...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.