Skip to content

Instantly share code, notes, and snippets.

@iam-peekay
Last active Apr 16, 2019
Embed
What would you like to do?
// lib/counter.js
var counter = 1;
function increment() {
counter++;
}
function decrement() {
counter--;
}
module.exports = {
counter: counter,
increment: increment,
decrement: decrement
};
// src/main.js
var counter = require('../../lib/counter');
counter.increment();
console.log(counter.counter); // 1
@Mr-tailor

This comment has been minimized.

Copy link

@Mr-tailor Mr-tailor commented Jul 27, 2018

counter.counter will have value of 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment