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
function outerScope() { | |
let a = "Hello" | |
console.log(a) // "Hello" | |
function innerScope() { | |
a = 3 | |
return | |
} |
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
var a = { | |
loop: (() => setInterval(() => console.log('It lives!'), 1000))() | |
} | |
console.log(a) | |
a = undefined | |
console.log(a) |
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
//global variable | |
const GlobalMembersArray =[]; | |
/** | |
* This creates a new Member. | |
* @class | |
* @classdesc A Member object. | |
* @param {Object} memberData - The data for the member to create. | |
* @param {string} memberData.id - The unique id of the member. | |
* @param {string} memberData.password - The member's password. |
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
//global variable | |
const GlobalMembersArray =[]; | |
/** | |
* Member type definition | |
* @typedef {Object} Member | |
* @property {string} id - The unique id of the member. | |
* @property {string} password - The member's password. | |
*/ |
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
//global variable | |
const GlobalMembersArray =[]; | |
/** | |
* Create a new member. | |
* @param {Object} memberData - The data for the member to create. | |
* @param {string} memberData.id - The unique id of the member. | |
* @param {string} memberData.password - The member's password. | |
*/ | |
function Member({id, password}){ |
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
//global variable | |
const GlobalMembersArray =[]; | |
// TypeScript types on function parameters | |
function Member({id, password}: {id: string, password: string}){ | |
this.id = id; | |
this.password = password | |
} | |
const member1 = new Member({id: "m001", password: "123"}); |
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
//global variable | |
const GlobalMembersArray =[]; | |
//object | |
function Member({id, password}){ | |
this.id = id; | |
this.password = password | |
} | |
const member1 = new Member({id: "m001", password: "123"}); |
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
//global variable | |
const GlobalMembersArray = []; | |
//object | |
function Member(id, password) { | |
this.id = id; | |
this.password = password | |
} | |
const member1 = new Member("m001","123"); |
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
const GlobalMemberStore = (() => { | |
let _members = [] | |
const needsArg = arg => { | |
if (!arg) { | |
throw new Error (`Undefined passed as argument to Store!`) | |
} | |
return arg | |
} | |
const needsId = member => { | |
if (!member.id) { |
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
const GlobalMemberStore = (() => { | |
let _members = [] | |
const Store = { | |
putMember: member => { | |
// Validate required args | |
const m = needsId(needsArg(member)) | |
if (Store.getMember(m.id).found) { | |
throw new Error(`${m.id} already exists!`) | |
} | |
_members = [..._members, {...m}] |