Closure Douglas Crockford. Block Scope { let a; { let b; … a … … b … } … a … }

Slides:



Advertisements
Similar presentations
TIME PAST O’CLOCK TO HALF TO HALF O’CLOCK PAST.
Advertisements

What time is it? What’s the time?
56 th AGM * “Future Vision.....Forward Movement” Your Name Here Your Title Here Your Company Here Add speech title.
Dr. Seuss: Tens and Ones.
What time is it? Coo-Coo one o'clock a quarter to seven
It’s nine o’clock
NUMBERS. 1 ONE Mariana T. Vilas Boas, Digital.
CLICK THE NUMBERS IN SEQUENCE
Beginning Decimals. Decimal means ten One tenth 1 / Two tenths 2 / Three tenths 3 / Four tenths 4 / Five tenths 5 /
REMEMBER: A number can be negative or positive as shown in the number line below: Negative Numbers (-) Positive Numbers (+)
HOW TO ADD INTEGERS REMEMBER:
Four Different Ways to Show a Number
Subtracting Across Zeros
Place value Units Tens Hundreds.
Proportions Round One 2) x + 3 = 15 Answers 2.) x + 3 = 15 X=12 21.
Zero 0 Show Me Zero One 1 Show Me 1 Two 2 Show Me 2.
Which of the following is 5,326 in word form? a) Five hundred two thirty six b) Five thousand, two hundred three six c) Five thousand, two thirty six.
Function the Ultimate Act III. Function Method Class Constructor Module.
Let’s learn about it. 10.
CLICK THE NUMBERS IN SEQUENCE
Jeopardy Place Value Words- Number Value Number – Words What digit Q $100 Q $200 Q $300 Q $400 Q $500 Q $100 Q $200 Q $300 Q $400 Q $500.
ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE TEN CLICK THE NUMBERS IN SEQUENCE.
Skip Counting Practice
Popcorn Words blue orange eight red purple nine.
What time is it ? in the morning / in the afternoon in the evening
From One to Ten… let’s count our Easter Eggs
START It’s two o’clock It’s a quarter to ten It’s five to eight It’s twenty to one.
2B: Unit 5 What time is it What time is it ? o’clock / half past.
Non-Standard Measurement
STANDARD 5 TH A SUBJECT -- MATHEMATICS
We count one, two, three….
Divisibility Rules.
Subtracting Across Zeros
Title of the poster. Title of the poster. Title of the poster
Subtraction Across a Zero
Subtracting Across Zeros
Like.
Subtraction Across a Zero
Number Words   two one three.
Title of the poster. Title of the poster. Title of the poster
Me in Two Words.
Beginning Decimals. Decimal means ten One tenth 1 / Two tenths 2 / Three tenths 3 / Four tenths 4 / Five tenths 5 /
Subtraction Across a Zero
NUMBERS one two three four five six seven eight
THE BUSY BEE BAŞLA The bee is very busy learning the numbers. Help her with the matching.
Connecting Number Words, Numerals and Models
Hello!!!.
TO PAST TELLING THE TIME.
WHAT TIME IS IT? OK NO! It's o’clock A quarter past
How many ?.
Which is best value for money?
Ms. Lindsey’s Kindergarten Class 11/1/16
Divisibility Rules.
CLICK THE NUMBERS IN SEQUENCE
CHOOSE THE CORRECT NUMBER
Presentation Title Presentation Title
Subtraction Across a Zero
Beginning Decimals.
What time is it ? o’clock / half past 2B: Unit 5.
MINUTES five past ten past quarter past 11 1 twenty past
+/- Numbers Year 6 – Place value, rounding and mental methods
CLICK THE NUMBERS IN SEQUENCE
Subtraction Across a Zero
TIME PAST O’CLOCK TO HALF TO HALF O’CLOCK PAST.
Multiplication facts Your Help Guide.
High Frequency Words - Kindergarten
Beginning Decimals.
PART-PART-WHOLE Example Version Developed by Graeme Henchel
+/- Numbers Year 3-4 – Addition and subtraction of hundreds within
NAPLAN PRACTISE Work through the problem with your group.
Presentation transcript:

Closure Douglas Crockford

Block Scope { let a; { let b; … a … … b … } … a … }

Function Scope function green() { let a; function yellow() { let b; … a … … b … } … a … }

Function Scope function green() { let a; function yellow() { let b; … a … … b … } … a … } a

Function Scope function green() { let a; function yellow() { let b; … a … … b … } … a … } a b

Lisp [1958] dynamic scope nested functions function values Algol 60 [1960] lexical scope nested functions functions are not values C [1972] lexical scope functions cannot nest functions are values

Inner survives the outer function green() { let a; return function yellow() { let b; … a … … b … }; … a … }

Global var names = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']; var digit_name = function (n) { return names[n]; }; alert(digit_name(3)); // 'three'

Slow var digit_name = function (n) { var names = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']; return names[n]; }; alert(digit_name(3)); // 'three'

Closure var digit_name = (function () { var names = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']; return function (n) { return names[n]; }; }()); alert(digit_name(3)); // 'three'

Start Over var names = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']; var digit_name = function (n) { return names[n]; }; alert(digit_name(3)); // 'three'

Immediate function returns a function var names = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']; var digit_name = (function () { return function (n) { return names[n]; }; }()); alert(digit_name(3)); // 'three'

Closure var digit_name = (function () { var names = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']; return function (n) { return names[n]; }; }()); alert(digit_name(3)); // 'three'