This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<!-- development version, includes helpful console warnings --> | |
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> | |
</head> | |
<body> |
This file contains 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
//es5 function expressiong | |
const funcAuth = function(email,password) { | |
//some logic | |
return 'You are login successfully'; | |
} | |
//funciton expression with es6 arrow function | |
const funcSing = (name) => { | |
return `${name} sings: La ala laaa`; | |
} |
This file contains 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 can be passed as argument | |
const sing = function(name) { | |
return `${name} is singing a song`; | |
} | |
const letPerson = function(name,fn) { | |
return fn(name); | |
} | |
letperson('Lorem',sing); |
This file contains 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 a() { | |
let grandFather = 'grandpa'; | |
return funciton b() { | |
let father = 'father'; | |
return function c() { | |
let son = 'son'; | |
return `${grandFather} > ${father} > ${son}`; | |
} | |
} | |
} |
This file contains 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 withOutClosure(index) { | |
const arr = new Array(8000).fill('Lorem ipsum olorem'); // some random heavy operation that generate data | |
return arr[index]; | |
} | |
withOutClosure(543); | |
withOutClosure(6543); | |
withOutClosure(345); | |
withOutClosure(135); |
This file contains 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 encapEg() { | |
let protectedData = 0; // this is the protected data that we only want to allow read access not direct change it | |
const accessTheData = () => protectedData; // this function will exported | |
const updateData = ()=> protectedData++; // we want to update the protected data internall | |
setInterval(updateData,1000); //this is the logic to update the data | |
return { | |
accessTheData // we return the function that only allow to access the protected data | |
} | |
} |
This file contains 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
let personA = { | |
first_name: "lorem", | |
last_name: "ipsum", | |
getFullName() { | |
return `Full Name is: ${this.first_name} ${this.last_name}`; | |
} | |
}; | |
let personB = { | |
first_name: "rutrum", |
This file contains 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
let Person = function(first_name,last_name) { | |
this.first_name = first_name; | |
this.last_name = last_name; | |
} | |
Person.prototype.getFullName = function() { | |
return `Full Name is: ${this.first_name} ${this.last_name}`; | |
} | |
let personA = new Person('lorem','ipsum'); | |
let personB = new Person('felis','ullamcorper'); |
This file contains 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
let person = { | |
first_name:'lorem', | |
last_name:'ipsum', | |
getFullName(){ | |
return `Fullname is ${this.first_name} ${this.last_name}`; | |
} | |
} | |
let personA = Object.create(person); | |
personA.first_name = 'ullamcorper'; //overwrite the person first_name property |
This file contains 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
class Person | |
{ | |
constructor(first_name,last_name) { | |
this.first_name = first_name; | |
this.last_name = last_name; | |
} | |
getFullName() { | |
return `Full Name is: ${this.first_name} ${this.last_name}`; | |
} | |
} |
OlderNewer