/**
* js samples for resig book - chapter 2
*/
/**
* REFERENCES ONLY POINT TO THE FINAL REFERRED OBJECT, NOT A REFERENCE ITSELF!
* A REFERENCE TRAVERSES DOWN THE REFERENCE CHAIN AND ONLY POINTS TO THE CORE OBJECT.
*/
/**
* 2.1 object references to single object
*/
var obj = new Object();
var objRef = obj;
obj.myGirls=['Makayla', 'Kathryn'];
//console.log(objRef);
/**
* 2.2 Array() is a self-modifying object that creates gloabl updates with
*/
// an internal method...push().
var items = ['one', 'two', 'three'];
var itemsRef = items;
//update items so all references get update
items.push('four');
//console.log(itemsRef);
/**
* 2.3 Changing the reference of an Object while maintaining integrity
*/
var moreItems = ['four', 'five', 'six'];
var moreItemsRef = moreItems;
//set moreItems to a new array object
moreItems = ['seven','eight','nine'];
//moreItems and moreItemsRef now points to different objects, while
//moreItemsRef maintains reference to original moreItems object
//console.log(moreItems);
//console.log(moreItemsRef);
/**
* 2.4 Object modification resulting in a NEW OBJECT, not a self-modifying object
* modified string() creates NEW OBJECT.
*/
// Set stringItem equal to a new string object
var stringItem = "test";
// stringItemRef now refers to the same string object
var stringItemRef = stringItem;
// Concatenate some new text onto the string object
// NOTE: This creates a new object, and does not modify the original object.
stringItem += "ing";
// The values of stringItem and stringItemRef are NOT equal, as a whole
// new string object has been created
//console.log(stringItem)
//console.log(stringItemRef);
/**
* Funciton Overloading and Type Checking
*/
/**
* Functions have a contextual variable: arguments. arguments is a pseudo
* array containing all the arguments passed into the function with access
* and .length.
*/
/**
* Function Overloading example
*/
//a simple function for sending a message...
function sendMessage( msg, obj ) {
...
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.