Skip to content

Instantly share code, notes, and snippets.

Questions

  • What is scope? Your explanation should include the idea of global vs. local scope.

    Scope is the concept of where a variable can be accessed. Variables should usually be created within the scope of a function instead of being created as properties of the global object ('window' in the browser). A local variable is one that has been declared in the context of the current function.

  • Why are global variables avoided?

    Global variables create many problems including unintended consequences and incompatibilities between libraries or files. They also make finding errors more difficult because it's harder to narrow down the source of some problems.

@benfletcher
benfletcher / index.js
Created December 16, 2016 22:19
Redux Thunk with Fetch - standalone demo
require('babel-polyfill');
import React from 'react';
import ReactDOM from 'react-dom';
import {createStore, applyMiddleware, compose} from 'redux';
import thunk from 'redux-thunk'
import {Provider, connect} from 'react-redux';
/************ ACTION CONSTANTS AND ACTION CREATORS ************/
const ADD_REPOSITORY = 'ADD_REPOSITORY';
const addRepository = repository => ({type: ADD_REPOSITORY, repository});

The future is here: Classless object-oriented programming in JavaScript.

Douglas Crockford, author of JavaScript: The Good parts, recently gave a talk called The Better Parts, where he demonstrates how he creates objects in JavaScript nowadays. He doesn't call his approach anything, but I will refer to it as Crockford Classless.

Crockford Classless is completely free of class, new, this, prototype and even Crockfords own invention Object.create.

I think it's really, really sleek, and this is what it looks like:

function dog(spec) {
@benfletcher
benfletcher / temp.md
Created December 18, 2016 20:27 — forked from mpj/temp.md
bah

5 tips to quickly understand a new code base

When you work as a programmer, it’s only a small percentage of your time that is spent on writing code. The vast majority of your time is spent trying to understand code that is already written. Either code of others, or code that you yourself wrote a last year.

It’s especially tricky to get into a completely new codebase. You might when you start a new job or perhaps your team takes ownership of a new system.

I have done this a couple of times now, and I have a process for it now, and I figure that it might be interesting to some people to hear about it, and that is what we are going to explore today.

In case you’re new - this is FunFunFunction, a weekly show where we try to become more confident and excited about programming by exploring old wisdom, wild ideas and having fun. At the end of this episode, I’m going to ask to subscribe.

@benfletcher
benfletcher / infinite.js
Created January 26, 2017 00:31 — forked from threepointone/infinite.js
infinite scrolling pattern with react fiber (featuring intersection observers)
// inifinite scrolling of content without extra wrappers
const { render, findDOMNode } = ReactDOMFiber
class App extends React.Component {
render() {
// wrap the root element with an Intersection Observer, exposing .observe for children
return <Intersection>
<div style={{ height: 200, overflow: 'auto' }}>
<Page offset={0} count={10} />
</div>