SlideShare ist ein Scribd-Unternehmen logo
1 von 47
Guy Royse, Consultant
Pillar Technology
groyse@pillartechnology.com
@guyroyse

Clean Code
TDD
JavaScript
People

Crufty Code
Working Alone
COBOL
Mean People
Source: http://xkcd.com/101/
Show
JavaScript
Problem

Someone
Tries to
Solve It
YES

Are They
Correct?

Dispense
Candy

Anymore
Problems?

NO

NO

Try Again

YES

Game Over
Rule #1
The first person
to answer correctly
wins
a candy bar.
Rule #2
You may not win more
than one candy bar.
So let others play the
game too.
Rule #3
If you break Rule #2,
I will give the candy bar
to the skinniest person
in the room.
Rule #4
If you break Rule #2
and are the skinniest
person in the room, I
will eat the candy bar.
Rule #5
In the event of any rules
dispute it is important
to remember,
I am always right.
Problem #1
varechoEchoEcho = function(value) {
varreturnValue = echoEchoEcho.lastValue;
echoEchoEcho.lastValue = value;
return returnValue;
}
var results = [];
results.push(echoEchoEcho('foo'));
results.push(echoEchoEcho('bar'));
results.push(echoEchoEcho('baz'));

a)
b)
c)
d)

undefined -- the code will throw an exception
[undefined, 'foo', 'bar']
['foo', 'bar', 'baz']
[null, 'foo', 'bar‘]
{}
new String('foo')
new Number(42)
new Boolean(true)
function()

'foo'
42
true and false
['foo', 42, false]
{}
var foo = new Object();
{}
var foo = {};
{}
var foo = {
bool : true,
num : 42,
text : 'some text',
func : function() { return 2 + 2 },
obj : { foo : 1, bar : 2 }
};
{}
var foo = { value : 42 };
foo.value = 23;
foo.otherValue = true;
delete foo.value;

// update
// create
// delete
{}
varfoo = { value : 42 };
varx = foo.value;
vary = foo['value'];

varval = 'value';
varz = foo[val];
{}
[]
Problem #2
var Policy = function() {
this.premium = 600;
this.term = 6;
this.calculateMonthlyAmount = function() {
return this.premium / this.term;
};
};
varmyPolicy = Policy();
varmyMonthlyAmount = myPolicy.calculateMonthlyAmount();

a)
b)
c)
d)

undefined -- the code will throw an exception
null
100
600
var balance = 200.00;
var Account = function(acctBalance) {
this.balance = acctBalance;
this.deposit = function(amount) {
this.balance += amount;
}
};
var myAcct = Account(500.00);
var myAcct = Account(0.0);
{}
var Policy = function(policyNumber) {
this.policyNumber = policyNumber;
this.compressPolicyNumber = function() {
return this.policyNumber.replace(' ', '');
};
};
var policy = new Policy();
{}
var createPolicy = function(policyNumber) {
this = {};
this.policyNumber = policyNumber;
this.compressPolicyNumber = function() {
return this.policyNumber.replace(' ', '');
};
return this;
};
{}
var Foo = function() {
if (!this instanceof Foo) {
return new Foo();
}
this.bar = 42;
this.baz = 'Hello, World!'
};
Problem #3
var principal = 5000;
var calculate = function() {
return this.principal * 0.10;
};
var account = { principal : 1000, interest : calculate };
var loan = { principal : 2000, charge : calculate };
var amount = account.interest() + loan.charge();

a)
b)
c)
d)

undefined -- the code will throw an exception
100
500
300
{}
function echo(value) {
return value;
}
{}
var echo = function(value) {
return value;
};
{}
var echo = function(value) {
return value;
};
var repeat = echo;
()
{}
var echo = function(value) {
return value;
};
echo('Hola, mundo!');
{}
var object = {
echo: function(value) { return value; }
};
object['echo']('Hola, mundo!');

var array = [object.echo];
array[0]('Hola, mundo!');
{}
var value = (function(value) {
return value;
})('Hello, World!');
Problem #4
varfoo = function() {
foo = function() {
return 'Polo!';
};
return 'Marco!';
};
var results = [];
results.push(foo());
results.push(foo());
results.push(foo());

a)
b)
c)
d)

undefined -- the code will throw an exception
['Marco!', 'Polo!', 'Polo!']
['Marco!', 'Polo!', 'Marco!]
['Polo!', 'Marco!', 'Polo!]
{}
var foo = function() {
foo = function() { return 'Polo!'; };
return 'Marco!';
};

var bar = foo;
bar();
{}
var foo = [1,2,3];
var bar = [];
foo.forEach(function(item) {
bar.push(item * 10);
});
// bar == [10, 20, 30]
{}
[].forEach(fn)
[].filter(fn)
[].every(fn)

[].some(fn)
[].sort(fn)

iterates every item
creates new array of items
where true is returned
iterates items
until false is returned
iterates items
until true is returned
comparator function
Problem #5
varfoo = (function() {
var count = 0;
var values = ['foo', 'bar', 'baz', 'qux'];
return function() {
count++;
return values[count];
};
})();
var results = [foo(), foo(), foo()];

a)
b)
c)
d)

undefined -- the code will throw an exception
['foo','bar','baz']
['bar','baz','qux']
['qux','baz','bar']
{}
varcreatePolicy = function(number) {
varpolicyNumber = number;
return {
getPolicyNumber: function() {
return policyNumber;
}
};
};
{}
var policy = (function() {
var policyNumber = '1234567890';
return {
getPolicyNumber: function() {
return policyNumber;
}
};
})();
{}
JavaScript: The Good Parts
Douglas Crockford

JavaScript Patterns
Stoyan Stefanov

Weitere ähnliche Inhalte

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 

Empfohlen

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

So You Think You Know JavaScript

  • 1.
  • 2. Guy Royse, Consultant Pillar Technology groyse@pillartechnology.com @guyroyse Clean Code TDD JavaScript People Crufty Code Working Alone COBOL Mean People
  • 3.
  • 5.
  • 6. Show JavaScript Problem Someone Tries to Solve It YES Are They Correct? Dispense Candy Anymore Problems? NO NO Try Again YES Game Over
  • 7. Rule #1 The first person to answer correctly wins a candy bar.
  • 8. Rule #2 You may not win more than one candy bar. So let others play the game too.
  • 9. Rule #3 If you break Rule #2, I will give the candy bar to the skinniest person in the room.
  • 10. Rule #4 If you break Rule #2 and are the skinniest person in the room, I will eat the candy bar.
  • 11. Rule #5 In the event of any rules dispute it is important to remember, I am always right.
  • 12.
  • 13. Problem #1 varechoEchoEcho = function(value) { varreturnValue = echoEchoEcho.lastValue; echoEchoEcho.lastValue = value; return returnValue; } var results = []; results.push(echoEchoEcho('foo')); results.push(echoEchoEcho('bar')); results.push(echoEchoEcho('baz')); a) b) c) d) undefined -- the code will throw an exception [undefined, 'foo', 'bar'] ['foo', 'bar', 'baz'] [null, 'foo', 'bar‘]
  • 14. {} new String('foo') new Number(42) new Boolean(true) function() 'foo' 42 true and false ['foo', 42, false]
  • 15. {} var foo = new Object();
  • 17. {} var foo = { bool : true, num : 42, text : 'some text', func : function() { return 2 + 2 }, obj : { foo : 1, bar : 2 } };
  • 18. {} var foo = { value : 42 }; foo.value = 23; foo.otherValue = true; delete foo.value; // update // create // delete
  • 19. {} varfoo = { value : 42 }; varx = foo.value; vary = foo['value']; varval = 'value'; varz = foo[val];
  • 20. {} []
  • 21.
  • 22. Problem #2 var Policy = function() { this.premium = 600; this.term = 6; this.calculateMonthlyAmount = function() { return this.premium / this.term; }; }; varmyPolicy = Policy(); varmyMonthlyAmount = myPolicy.calculateMonthlyAmount(); a) b) c) d) undefined -- the code will throw an exception null 100 600
  • 23.
  • 24. var balance = 200.00; var Account = function(acctBalance) { this.balance = acctBalance; this.deposit = function(amount) { this.balance += amount; } }; var myAcct = Account(500.00); var myAcct = Account(0.0);
  • 25.
  • 26. {} var Policy = function(policyNumber) { this.policyNumber = policyNumber; this.compressPolicyNumber = function() { return this.policyNumber.replace(' ', ''); }; }; var policy = new Policy();
  • 27. {} var createPolicy = function(policyNumber) { this = {}; this.policyNumber = policyNumber; this.compressPolicyNumber = function() { return this.policyNumber.replace(' ', ''); }; return this; };
  • 28. {} var Foo = function() { if (!this instanceof Foo) { return new Foo(); } this.bar = 42; this.baz = 'Hello, World!' };
  • 29. Problem #3 var principal = 5000; var calculate = function() { return this.principal * 0.10; }; var account = { principal : 1000, interest : calculate }; var loan = { principal : 2000, charge : calculate }; var amount = account.interest() + loan.charge(); a) b) c) d) undefined -- the code will throw an exception 100 500 300
  • 31. {} var echo = function(value) { return value; };
  • 32. {} var echo = function(value) { return value; }; var repeat = echo;
  • 33. ()
  • 34. {} var echo = function(value) { return value; }; echo('Hola, mundo!');
  • 35. {} var object = { echo: function(value) { return value; } }; object['echo']('Hola, mundo!'); var array = [object.echo]; array[0]('Hola, mundo!');
  • 36. {} var value = (function(value) { return value; })('Hello, World!');
  • 37. Problem #4 varfoo = function() { foo = function() { return 'Polo!'; }; return 'Marco!'; }; var results = []; results.push(foo()); results.push(foo()); results.push(foo()); a) b) c) d) undefined -- the code will throw an exception ['Marco!', 'Polo!', 'Polo!'] ['Marco!', 'Polo!', 'Marco!] ['Polo!', 'Marco!', 'Polo!]
  • 38.
  • 39. {} var foo = function() { foo = function() { return 'Polo!'; }; return 'Marco!'; }; var bar = foo; bar();
  • 40. {} var foo = [1,2,3]; var bar = []; foo.forEach(function(item) { bar.push(item * 10); }); // bar == [10, 20, 30]
  • 41. {} [].forEach(fn) [].filter(fn) [].every(fn) [].some(fn) [].sort(fn) iterates every item creates new array of items where true is returned iterates items until false is returned iterates items until true is returned comparator function
  • 42. Problem #5 varfoo = (function() { var count = 0; var values = ['foo', 'bar', 'baz', 'qux']; return function() { count++; return values[count]; }; })(); var results = [foo(), foo(), foo()]; a) b) c) d) undefined -- the code will throw an exception ['foo','bar','baz'] ['bar','baz','qux'] ['qux','baz','bar']
  • 43.
  • 44. {} varcreatePolicy = function(number) { varpolicyNumber = number; return { getPolicyNumber: function() { return policyNumber; } }; };
  • 45. {} var policy = (function() { var policyNumber = '1234567890'; return { getPolicyNumber: function() { return policyNumber; } }; })();
  • 46.
  • 47. {} JavaScript: The Good Parts Douglas Crockford JavaScript Patterns Stoyan Stefanov

Hinweis der Redaktion

  1. Caveats - you’re going to learn some JavaScript stuff here - showing some of the cool features and misfeatures of JavaScript - not about what you should or shouldn't do -- for that you need to use your brain and maybe read some books for some guidance - not about HTML and the DOM
  2. I Thought I Knew JavaScript could write function knew the syntax manipulate the DOM even use jQuery and prototypeBut I was wrong. There is a lot more going on. I had barely scratched the surface. In this session we are going to do more than scratch the surface.Talk will be about advance method invocations, objects and classes, closures, and prototypes if we have time.Discovered some cool stuff in learning JavaScript and today I’m going to share it in…..
  3. Caveats - you’re going to learn some JavaScript stuff here - showing some of the cool features and misfeatures of JavaScript - not about what you should or shouldn't do -- for that you need to use your brain and maybe read some books for some guidance - not about HTML and the DOM
  4. How it works - I present some sample code with multiple outcomes - you select the correct answer - I give out prizes
  5. Everything is an object - even arrays, functions, numbers, strings, booleans
  6. Defining an object - new Object();
  7. Defining an object - this is overkill, probably easier to just do this.
  8. Defining an object - and adding a few properties is easy from here – this is called an object literal or the module pattern
  9. Add, update, remove
  10. Accessing an object - simple dot notation - array notation - “reflection”
  11. Objects are not arrays – arrays are objects
  12. Why did this fail? - we didn't use the new operator - this is a really easy mistake to make - but the error wasn't in the penultimate line, it was in the last line - Policy is just a function - but what happened to what we assigned to this?
  13. The default value for this is the global namespace (i.e. everywhere) - if you are in a browser this is window
  14. This could be really bad for either the bank, or the customerThis is a common mistake and easy to make and it occurs because classes are really just a fiction in JavaScript.
  15. What we really have is a specialized constructor function
  16. By convention always capitalize class names - this is just code, nothing special – anything could go in here - this is defined as the object instance that was created
  17. - this is what is really happening - there is actually a bit more happening here involving prototypes but we'll not get into that today
  18. Function calls are easy to define - function keyword
  19. Function calls are easy to define- assigning it to a variable - a bit more honest -- because they are easy to reassign
  20. Function calls are easy to define - because they are easy to reassign
  21. This is the key to invoking functions
  22. Function calls are easy - just use () at the end of a variable
  23. Function calls are easy - you can call functions on an object or in an array this way too
  24. You can even call them on the fly using immediately executing functions
  25. These are cool, but they can not work as expected so be careful
  26. This code illustrates the problem – calling bar will always return 'Marco!'
  27. Functions can be passed as arguments - create for using the strategy pattern
  28. Functions can be passed as arguments - create for using the strategy pattern
  29. A closure is a bit of code and variables that should otherwise be out of scope
  30. Closures are great for private variables in JavaScript - policy number is now read only and not modifiable for this object
  31. AKA the revealing module patternCombining closures and immediately invoked functions makes for wicked cool singletons - why, then we don't need a function to construct the object - this keeps the global namespace clean - and keeps others from calling code you don't intend to be called - it's the same as a protected constructor in Java
  32. Functions can be passed as arguments - create for using the strategy pattern