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
// This is a simple *viewmodel* - JavaScript that defines the data and behavior of your UI | |
function AppViewModel() { | |
this.lastName = ko.observable("Bertington"); | |
this.capitalizeLastName = function() { | |
var currentVal = this.lastName(); // Read the current value | |
this.lastName(currentVal.toUpperCase()); // Write back a modified value | |
}; | |
} | |
// Activates knockout.js |
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
var parts = ['shoulders', 'knees']; | |
var parts2 = ['head', 'and', 'toes']; | |
// ES 5 | |
var lyrics = parts2.slice(0, 1).concat(parts).concat(parts2.slice(1, 3)); | |
console.log(lyrics); // ["head", "shoulders", "knees", "and", "toes"] | |
// ES 6 | |
var lyrics = [parts2[0], ...parts, parts2[1], parts2[2]]; | |
console.log(lyrics); // ["head", "shoulders", "knees", "and", "toes"] |
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
// Mutated Version | |
const combineReducers = reducers => { | |
return (state = {}, action) => { | |
return Object.keys(reducers).reduce((nextState, key) => { | |
nextState[key] = reducers[key](state[key], action) | |
return nextState | |
}, {}) | |
} | |
}; |
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
// npm i node-uuid | |
var uuid = require('node-uuid'); | |
// Generate a v1 (time-based) id | |
uuid.v1(); | |
// Generate a v4 (random) id | |
uuid.v4(); |
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 ViewSomething() { | |
this.a = 42 | |
this.click = function() => { | |
alert(this.a) // undefined | |
} | |
this.click1 = () => { | |
alert(this.a) // 42 |
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
'use strict'; | |
function chain() { | |
var newReleases = [{ | |
"id": 70111470, | |
"title": "Die Hard", | |
"rating": 4.0 | |
}, { | |
"id": 654356453, | |
"title": "Bad Boys", |
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
'use strict'; | |
function mul(x) { | |
return x * x; | |
} | |
function mulWVariance(variance, x) { | |
return x * x + variance; | |
} |
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
'use strict'; | |
var express = require('express'); | |
var compression = require('compression'); | |
var app = express(); | |
var oneYear; | |
// gzip the static resources before seding to browser, if the browser supports gzip compression |
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
// Returns a function, that, as long as it continues to be invoked, will not be triggered. | |
// The function will be called after it stops being called for N milliseconds. | |
function debounce (cb, wait) { | |
var timeoutID | |
return function () { | |
clearTimeout(timeoutID) | |
timeoutID = setTimeout(cb, wait) | |
} |
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
'use strict' | |
function f1 () { | |
console.log('f1 called'); | |
return false; | |
} | |
function f2 () { | |
console.log('f2 called'); |