es6 closures
JavaScript
var makeCounter = function() {
var privateCounter = 0;
function changeBy(val) {
privateCounter += val;
}
return {
increment: function() {
changeBy(1);
},
decrement: function() {
changeBy(-1);
},
value: function() {
return privateCounter;
}
}
};
var counter1 = makeCounter();
var counter2 = makeCounter();
alert(counter1.value()); /* Alerts 0 */
counter1.increment();
counter1.increment();
alert(counter1.value()); /* Alerts 2 */
counter1.decrement();
alert(counter1.value()); /* Alerts 1 */
alert(counter2.value()); /* Alerts 0 */
Also in JavaScript:
- Title
- javascript check empty object
- Category
- JavaScript
- Title
- How to check whether a checkbox is checked in jQuery?
- Category
- JavaScript
- Title
- ajax with progress bar
- Category
- JavaScript
- Title
- javascript check if array is empty
- Category
- JavaScript
- Title
- create react component class
- Category
- JavaScript
- Title
- check array values equal js
- Category
- JavaScript
- Title
- form submit programmatically
- Category
- JavaScript
- Title
- javascript add scroll listener
- Category
- JavaScript
- Title
- flatten nested object js
- Category
- JavaScript
- Title
- how to append select option in jquery
- Category
- JavaScript
- Title
- changing columns for table requires doctrine dbal install doctrine/dbal
- Category
- JavaScript
- Title
- how to delete an element of an array in javascript
- Category
- JavaScript
- Title
- area of a circle
- Category
- JavaScript
- Title
- jason rpc reactjs
- Category
- JavaScript
- Title
- array spread operator in javascript
- Category
- JavaScript
- Title
- focus js
- Category
- JavaScript
- Title
- how to expire a cookie in javascript
- Category
- JavaScript
- Title
- int cating javascript
- Category
- JavaScript
- Title
- array methods in javascript
- Category
- JavaScript
- Title
- javascript array of objects access properties
- Category
- JavaScript
- Title
- how to check if a number is even or odd in javascript
- Category
- JavaScript
- Title
- disable autocomplete in react fields
- Category
- JavaScript
- Title
- how to add prototype in javascript
- Category
- JavaScript
- Title
- javascript clear file input
- Category
- JavaScript
- Title
- Hoisting in JavaScript MDN
- Category
- JavaScript
- Title
- angular submit form programmatically
- Category
- JavaScript
- Title
- email validation regex
- Category
- JavaScript
- Title
- create table jquery
- Category
- JavaScript
- Title
- how to validate date in react
- Category
- JavaScript
- Title
- javascript change attribute
- Category
- JavaScript
- Title
- html how to type a long string in many lines
- Category
- JavaScript
- Title
- call js
- Category
- JavaScript
- Title
- fizz buzz javascript
- Category
- JavaScript
- Title
- how to use style in react js
- Category
- JavaScript
- Title
- javascript add nd st th to number
- Category
- JavaScript
- Title
- javascript check if array is in array
- Category
- JavaScript
- Title
- express fingerprint
- Category
- JavaScript
- Title
- form validation react
- Category
- JavaScript
- Title
- javascript add class to element
- Category
- JavaScript
- Title
- how to write in js
- Category
- JavaScript
- Title
- how to add a class to html using javascript
- Category
- JavaScript
- Title
- how to limit characters in number input js
- Category
- JavaScript
- Title
- how to place text at custom position on canvas in javascript
- Category
- JavaScript
- Title
- create a customer in stripe node.js
- Category
- JavaScript
- Title
- how to save thing in cookie js
- Category
- JavaScript
- Title
- create node project
- Category
- JavaScript
- Title
- empty array javascript
- Category
- JavaScript
- Title
- how to draw a triangle using javascript
- Category
- JavaScript
- Title
- if str contains jquery
- Category
- JavaScript
- Title
- electron jquery
- Category
- JavaScript
- Title
- hasownproperty.call
- Category
- JavaScript
- Title
- How to rewrite a function using arrow function syntax
- Category
- JavaScript
- Title
- * http://sizzlejs.com/
- Category
- JavaScript
- Title
- console log all array values node
- Category
- JavaScript
- Title
- if else practice javascript
- Category
- JavaScript
- Title
- daterangepicker set maxdate
- Category
- JavaScript
- Title
- group by in javascript
- Category
- JavaScript
- Title
- google maps react
- Category
- JavaScript
- Title
- bind jquery trough name
- Category
- JavaScript
- Title
- debug node
- Category
- JavaScript
- Title
- add month date now javascript
- Category
- JavaScript
- Title
- how to substract date object javascript
- Category
- JavaScript
- Title
- installing vue router & implementation
- Category
- JavaScript
- Title
- greater than or equal to javascript
- Category
- JavaScript
- Title
- duplicate encoder
- Category
- JavaScript
- Title
- angular build production
- Category
- JavaScript
- Title
- export default react
- Category
- JavaScript
- Title
- how to do a classname variable and string react
- Category
- JavaScript
- Title
- if (req.url === "/script.js")
- Category
- JavaScript
- Title
- date picker javascript not working
- Category
- JavaScript
- Title
- ellipsis javascript
- Category
- JavaScript
- Title
- how to add button in alert box in react native
- Category
- JavaScript
- Title
- add element to array javascript
- Category
- JavaScript
- Title
- angular rebuild
- Category
- JavaScript
- Title
- change js to json
- Category
- JavaScript
- Title
- ExoPlayer with auto linking react native
- Category
- JavaScript
- Title
- boucle foreach js
- Category
- JavaScript
- Title
- javascript exercism.io bob solution
- Category
- JavaScript
- Title
- chart.js radar chart
- Category
- JavaScript
- Title
- google sign in in firebase react
- Category
- JavaScript
- Title
- capturar el valor de un input con jquery
- Category
- JavaScript
- Title
- how to use for of in javascript
- Category
- JavaScript
- Title
- how to add class to element on mouseclick with js
- Category
- JavaScript
- Title
- how to access the second class of an element javascript
- Category
- JavaScript
- Title
- gitignore for angular
- Category
- JavaScript
- Title
- access angular app outside localhost
- Category
- JavaScript
- Title
- get current url js
- Category
- JavaScript
- Title
- error Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\]react[\\\]dist[\\\].*|website\\node_modules\\.*|heapCapture\\bundle\.js|.*\\__tests__\\.*)$/: Unterminated character class.
- Category
- JavaScript
- Title
- create a form and submit it dynamically jquery
- Category
- JavaScript
- Title
- deny ready jquery
- Category
- JavaScript
- Title
- get unique id angular
- Category
- JavaScript
- Title
- expo app.json
- Category
- JavaScript
- Title
- add table row jQuery
- Category
- JavaScript
- Title
- how to deploy react app in tomcat server
- Category
- JavaScript
- Title
- array to comma separated list js
- Category
- JavaScript
- Title
- how to write a program that alerts the first 3 letters of the current day in javascript
- Category
- JavaScript
- Title
- declare function javascript
- Category
- JavaScript
- Title
- how do I use const in javascript
- Category
- JavaScript
- Title
- delete node between indexes node list js
- Category
- JavaScript
- Title
- javascript addeventlistener
- Category
- JavaScript