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 elements = ['foo', 'bar', 'baz'] | |
for(i=0; i < elements.length; i++){ | |
elements[i].setClick(function(){ | |
alert(i); | |
}); | |
} | |
elements[0].click(); // what happens? |
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 vimBinding = document.createElement('script'); | |
vimBinding.setAttribute('src','https://raw.github.com/marijnh/CodeMirror/master/keymap/vim.js'); | |
var mirrors = document.querySelectorAll('.CodeMirror'); | |
// browser support for onload may be iffy ... | |
vimBinding.onload = function () { | |
Array.prototype.forEach.call(mirrors, function (instance){ | |
instance.CodeMirror.setOption('keyMap','vim'); |
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
<% _.forEach(projects, function (project) {%> | |
.<%= project.name %> { | |
background-img: url('img/projects/<%= project.img %>'); | |
<% }); %> |
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
// Implement an exclusive OR function called `preferredName` that has the following interface: | |
var FirstName, | |
LastName; | |
preferredName(FirstName, LastName); | |
// -> false | |
FirstName = 'Hank'; |
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
// Given the following data structure | |
// implement a oldestLivingFather method | |
// that will return the name of the oldest | |
// living father. | |
var people = [ | |
{ | |
name: 'Hank', | |
age: 29, | |
father: 'Don' |
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
// Implement a decorator function that takes | |
// a function as an argument and will track | |
// how many times the passed function was called. | |
function Add(x, y) { | |
return x + y; | |
} | |
var Add = countDecorator(Add); |
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
// Write a function that takes in a string seperated by a seperator, and will return an array | |
// of strings in between the seperators. | |
var sampleInput = 'asdf$lskd1234$asdo'; | |
stringDelemiter(sampleInput, '$'); | |
// -> ['asdf', 'lskd1234', 'asdo'] |
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 oldestLivingParent(people) { | |
var livingParents = {}; | |
var sortedByAge = []; | |
var oldestLivingParent = false; | |
var isDead = function(p) { | |
return !person.age; | |
}; | |
var isParent = function(p) { | |
return !!livingParent[p.name]; | |
}; |
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
find . -type f -exec sed -i -e 's%../app/%./%g' {} \; | |
find . -type f -exec sed -i -e 's%../build/%./views/%g' {} \; | |
find . -type f -exec sed -i '' -e 's%this.getDOMNode()%ReactDOM.findDOMNode(this)%g' {} \; | |
// osx sed -i expects an extension | |
// Illegal command try export LANG=C |
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 wat = React.createClass({ | |
render: function() { | |
return <div className="wat" onClick={function() {console.log('hi')}}/> | |
} | |
}); | |
ReactTestUtils.renderIntoDocument(<wat/>); | |
var huh = ReactTestUtils.scryRenderedDOMComponentsWithTag(wat, 'div'); | |
ReactTestUtils.Simulate.click(huh); | |
// Error: InstanceHandle not injected before use! |
OlderNewer