Skip to content

Instantly share code, notes, and snippets.

View bruceharris's full-sized avatar

Bruce Harris bruceharris

View GitHub Profile
@bruceharris
bruceharris / 02.asciidoc
Created July 30, 2012 19:46
JavaScript I - Variables, Functions, and Scope

JavaScript II - Objects, Arrays and Booleans

Content and target audience

JavaScript II - Objects, Arrays, and Booleans

Laying the foundation for object oriented programing in JavaScript.

@bruceharris
bruceharris / index.md
Created December 12, 2012 04:13
JavaScript's Prototype System

JavaScript's Prototype System

When I ask interview candidates to explain what prototypes mean in JavaScript, the response is often something like this

Here's my attempt to explain it succinctly.

I think it's important to draw the distinction between 2 related concepts: the prototype property of functions, and the prototype of an object

The prototype property of functions

@bruceharris
bruceharris / index.html
Created December 15, 2012 23:55
objectDiff
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Spec Runner</title>
<link rel="shortcut icon" type="image/png" href="lib/jasmine-1.2.0/jasmine_favicon.png">
<link rel="stylesheet" type="text/css" href="lib/jasmine-1.2.0/jasmine.css">
<script type="text/javascript" src="lib/jasmine-1.2.0/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-1.2.0/jasmine-html.js"></script>
package net.bruceharris.test.inheritance;
import static org.junit.Assert.assertEquals;
import org.junit.Assert;
import org.junit.Test;
public class InheritanceTest {
private Child c = new Child();
@bruceharris
bruceharris / README.md
Last active December 21, 2015 08:39
Does Meteor namespacing work as documented?

Meteor namespacing, specifically package scope variables, don't seem to work as described in the namespacing section of the docs.

From what I can tell, when the var keyword is omitted, actual globals are created. (I'm running 0.6.5)

To run this:

$ meteor create globalcheck

then copy these files into globalcheck (overwriting the default files)

@bruceharris
bruceharris / README.md
Last active January 3, 2016 06:29 — forked from mbostock/.block
@bruceharris
bruceharris / protips.js
Last active May 4, 2016 00:43 — forked from nolanlawson/protips.js
Promise protips - stuff I wish I had known when I started with Promises
// Promise.all is good for executing many promises at once
Promise.all([
promise1,
promise2
]);
// Promise.resolve is good for wrapping synchronous code
Promise.resolve().then(function () {
if (somethingIsNotRight()) {
throw new Error("I will be rejected asynchronously!");
@bruceharris
bruceharris / LoadingIndicator.js
Created March 2, 2018 15:49
React Unit Testing Example 3
import React, { Component } from 'react';
import PropTypes from 'prop-types';
export default class LoadingIndicator extends Component {
render() {
return this.props.children;
}
}
LoadingIndicator.propTypes = {
@bruceharris
bruceharris / LoadingIndicator.js
Last active March 2, 2018 15:51
React Unit Testing Example 1
import React, { Component } from 'react';
import PropTypes from 'prop-types';
export default class LoadingIndicator extends Component {
render() {
return null;
}
}
LoadingIndicator.propTypes = {
@bruceharris
bruceharris / LoadingIndicator.test.js
Last active March 2, 2018 15:51
React Unit Testing Example 2
import React from 'react';
import { mount } from 'enzyme';
import LoadingIndicator from './LoadingIndicator'
describe('LoadingIndicator', () => {
describe('when isLoading is false', () => {
it('should render children', () => {
const wrapper = mount(
<LoadingIndicator isLoading={false}>
<div>ahoy!</div>