JSFiddle - React, Tailwind, and code Playground

OOP-: Ch3- Understanding Objects

by nickadeemus2002

JavaScript

/**
 * 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 =...