Skip to content

Instantly share code, notes, and snippets.

View savelee's full-sized avatar

Lee Boonstra savelee

View GitHub Profile
@savelee
savelee / new.js
Last active July 25, 2016 14:06
Example default parameters
//ES2015
function makeRequest(url, timeout = 2000, callback = function(){}) {
//do something
}
@savelee
savelee / new.js
Last active July 25, 2016 14:04
Example of template literals
//ES2015
let product = "Sencha";
let myText = `${product} provides the industry's most comprehensive collection of high-performance, customizable UI widgets.
These "widgets" include HTML5 grids, trees, lists, forms, menus, toolbars, panels, windows, and much more.
If you don't find a widget you are looking for, hundreds of user extensions are available from the Sencha community.`;
@savelee
savelee / taggedtemplate.js
Last active July 25, 2016 14:05
Example Tagged Templates (template functions)
//ES2015
function myTag(arrLiterals){
return arrLiterals[0].toUpperCase();
}
let message = myTag`hello world!`; //HELLO WORLD!
@savelee
savelee / new.js
Last active July 25, 2016 14:02
Example of Arrow Functions
//ES6 arrow functions
var calculate = (x,y) => {
return x + y;
}
var sayHello = (name) => {
return "Hello " + name;
}
//or:
@savelee
savelee / new.js
Last active July 25, 2016 14:00
Arrow Functions: No duplicate named arguments. Arrow functions cannot have duplicate named arguments in strict or nonstrict mode, as opposed to non-arrow functions that cannot have duplicate named arguments only in strict mode
//ES2015
var x = (x,x) => x;
//SyntaxError: duplicate argument names not allowed in this context
@savelee
savelee / new.js
Last active July 25, 2016 13:59
Arrow Functions: No arguments object, since arrow functions have no arguments binding, you must rely on named and rest parameters to access function arguments.
//ES2015
var foo = (x,y) => arguments[0];
foo("lee","2") //ReferenceError: arguments is not defined [Learn More]
@savelee
savelee / new.js
Last active July 25, 2016 13:56
Lexical This
//ES2015
function VideoGame(){
this.title = "Uncharted";
this.version = 3;
setInterval(() => {
console.log(this.title + " " + this.version++); // |this| properly refers to the VideoGame object
}, 5000);
}
@savelee
savelee / new.js
Last active July 25, 2016 15:01
Example of destructuring
//ES5
var myobject = {
name: "Sencha",
logo: {
small: {
png: 'http://path/to/small.png',
jpg: 'http://path/to/small.jpg'
},
large: {
png: 'http://path/to/large.png',
@savelee
savelee / new.js
Created July 25, 2016 14:50
Example of array destructering
var myarray = ["Ext JS", "GXT", "Sencha Test"];
var [myvar1, myvar2, myvar3] = myarray;
console.log(myvar1) //Ext JS
console.log(myvar2) //GXT
console.log(myvar3) //Sencha Test
@savelee
savelee / new.js
Created July 26, 2016 07:09
Enhanced Object literals
//ES2015
function getVideoGame(title, version, platform) {
return {
title,
version,
platform
};
}
getVideoGame("Uncharted", "4", "PS4")