Created
May 2, 2022 01:33
-
-
Save lynsei/345146f61f221a5d441091f642199c49 to your computer and use it in GitHub Desktop.
[my favorite things, these are a few of them] #iffe #js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// IIFE: Immediately invoked, functional expr | |
var counter = (function(){ | |
var i = 0; | |
return { | |
get: function(){ | |
return i; | |
}, | |
set: function( val ){ | |
i = val; | |
}, | |
increment: function() { | |
return ++i; | |
} | |
};})(); | |
// 'counter' is an object with properties, which in this case happen to be// methods. | |
counter.get(); // 0 | |
counter.set( 3 ); | |
counter.increment(); // 4 | |
counter.increment(); // 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment