Skip to main content
added 99 characters in body
Source Link
radarbob
  • 8.2k
  • 21
  • 35
// Imagine you're in a war and 
// the guy next to you must always load
// your rifle for you. You're gonna die!
// So why do that with objects?

// Just give me the bullets and I will load them
// when, where, if, and how I need too.
// Pass constructor parameters!
// Now the client does not have to know 
//   A) there's an array in there and
//   B) What method(s) to call so the program doesn't blow up.


var sections = new options(optionA, optionB, optionC);
console.log("Average: ${sections.average()}");
// Imagine you're in a war and 
// the guy next to you must always load
// your rifle for you. You're gonna die!
// So why do that with objects?

// Pass constructor parameters!
// Now the client does not have to know 
//   A) there's an array in there and
//   B) What method(s) to call so the program doesn't blow up.


var sections = new options(optionA, optionB, optionC);
console.log("Average: ${sections.average()}");
// Imagine you're in a war and 
// the guy next to you must always load
// your rifle for you. You're gonna die!
// So why do that with objects?

// Just give me the bullets and I will load them
// when, where, if, and how I need too.
// Pass constructor parameters!
// Now the client does not have to know 
//   A) there's an array in there and
//   B) What method(s) to call so the program doesn't blow up.


var sections = new options(optionA, optionB, optionC);
console.log("Average: ${sections.average()}");
added 402 characters in body
Source Link
radarbob
  • 8.2k
  • 21
  • 35
var optionA = new option (scoreOptionA, weighting);
var optionB = new option (scoreOptionB, weighting);
var optionC = new option (scoreOptionC, weighting);

// imagine average() called as part of the output
console.log(optionA.toString()); 
console.log(optionB.toString()); 
console.log(optionC.toString()); 

// here, client code has to do all the work.
// imagine how many different ways it could be written
// and the potential for errors. Note the code will
// blow up when the array is empty; a simple edge case that 
// would have been accounted for if a "coherent" (google that)
// sections object was created and debugged.
var sum, average = 0;
var options = [];
options.push(optionA, optionB, optionC);
options.forEach(option => {sum += option.score});
average = sum / options.length;   
console.log("Average: ${average}");

// Calculating average usingwithin ana `options`sections object,
// Comprehension improvement is obvious when 
// operation details are wrapped in the object's functions 

var sections = new options();
sections.push(optionA, optionB, optionC);
console.log("Average: ${sections.average()}");
var optionA = new option (scoreOptionA, weighting);
var optionB = new option (scoreOptionB, weighting);
var optionC = new option (scoreOptionC, weighting);


console.log(optionA.toString()); 
console.log(optionB.toString()); 
console.log(optionC.toString()); 


var sum, average = 0;
var options = [];
options.push(optionA, optionB, optionC);
options.forEach(option => {sum += option.score});
average = sum / options.length;   
console.log("Average: ${average}");

// Calculating average using an `options` object
// Comprehension improvement is obvious when 
// operation details are wrapped in the object's functions 

var sections = new options();
sections.push(optionA, optionB, optionC);
console.log("Average: ${sections.average()}");
var optionA = new option (scoreOptionA, weighting);
var optionB = new option (scoreOptionB, weighting);
var optionC = new option (scoreOptionC, weighting);

// imagine average() called as part of the output
console.log(optionA.toString()); 
console.log(optionB.toString()); 
console.log(optionC.toString()); 

// here, client code has to do all the work.
// imagine how many different ways it could be written
// and the potential for errors. Note the code will
// blow up when the array is empty; a simple edge case that 
// would have been accounted for if a "coherent" (google that)
// sections object was created and debugged.
var sum, average = 0;
var options = [];
options.push(optionA, optionB, optionC);
options.forEach(option => {sum += option.score});
average = sum / options.length;   
console.log("Average: ${average}");

// Calculating average within a sections object,
// Comprehension improvement is obvious when 
// operation details are wrapped in the object's functions 

var sections = new options();
sections.push(optionA, optionB, optionC);
console.log("Average: ${sections.average()}");
added 143 characters in body
Source Link
radarbob
  • 8.2k
  • 21
  • 35

Objects are just a way to organize data/properties AND associated functions. Objects without functionality isObjects without functionality is like a day without sunshine. Otherwise it's like looking at an auto parts catalog and calling it a day without sunshinecar; it is not a car until it can do things (methods).

Objects are just a way to organize data/properties AND associated functions. Objects without functionality is like a day without sunshine.

Objects are just a way to organize data/properties AND associated functions. Objects without functionality is like a day without sunshine. Otherwise it's like looking at an auto parts catalog and calling it a car; it is not a car until it can do things (methods).

Lock and Load!
Source Link
radarbob
  • 8.2k
  • 21
  • 35
Loading
added 687 characters in body
Source Link
radarbob
  • 8.2k
  • 21
  • 35
Loading
added 687 characters in body
Source Link
radarbob
  • 8.2k
  • 21
  • 35
Loading
added 687 characters in body
Source Link
radarbob
  • 8.2k
  • 21
  • 35
Loading
added 423 characters in body
Source Link
radarbob
  • 8.2k
  • 21
  • 35
Loading
deleted 5 characters in body
Source Link
radarbob
  • 8.2k
  • 21
  • 35
Loading
deleted 3 characters in body
Source Link
radarbob
  • 8.2k
  • 21
  • 35
Loading
Source Link
radarbob
  • 8.2k
  • 21
  • 35
Loading