Skip to content

Instantly share code, notes, and snippets.

@Jiert
Jiert / factory-composition.js
Created October 5, 2015 18:43
Composition using factory functions
var barker = function(state){
return { bark: function(){ console.log('Woof, I am ' + state.name); } };
};
var driver = function(state){
return { drive: function(){
state.position = state.position + state.speed;
console.log(state.position);
} };
};
@Jiert
Jiert / composition-object-assign.js
Last active April 14, 2020 23:42
Composition using factory functions and Object.assign()
var runner = function(){
return {
run: function(){
console.log(this.name + ' is running away!');
}
};
};
var swimmer = function(){
return {
@Jiert
Jiert / alien-dictionary.js
Last active January 12, 2017 15:54
Alien Dictionary
var words = [
"wrt",
"wrf",
"er",
"ett",
"rftt"
]
var alphabet = []
var hash = {};
@Jiert
Jiert / stringify.js
Created February 2, 2017 21:12
Stringify
// Implement JSON.stringify
var example = {
"array": [1, 2, 3],
"number": 123,
"object": {
"a": "b",
"c": "d",
"e": "f"
},
"string": "Hello World"
@Jiert
Jiert / Sidebar.js
Last active May 8, 2017 16:46
How to use hashed with Redux
// URL hash should be the keeper of its own state. In this example we're using the "comparing" state,
// i.e. are we in compare mode or not. Since the toggle button lives in the sidebar, we would do something
// like this in the sidebar component:
getInitialState() {
comparing: false
}
componentWillMount() {
this.updateHash = hashed.register({comparing: false}, this.onHashChange);