Skip to content

Instantly share code, notes, and snippets.

View mroderick's full-sized avatar

Morgan Roderick mroderick

View GitHub Profile
@mroderick
mroderick / sinon-array-test.js
Created August 9, 2017 08:24
A sample which shows that you cannot stub the `Array.prototype.filter` method. All works fine for `Array.prototype.map`.
'use strict';
const sinon = require( 'sinon' );
const expect = require( 'chai' ).expect;
describe( 'Array.prototype', () => {
describe( 'map()', () => {
it( 'uses native map', () => {
const callback = sinon.spy();
const stub = sinon.stub( Array.prototype, 'map' ).returns( [ 2, 4 ] );

How to add an image to a gist

  1. Create a gist if you haven't already.
  2. Clone your gist:
    # make sure to replace `<hash>` with your gist's hash
    git clone https://gist.github.com/<hash>.git # with https
    git clone git@gist.github.com:<hash>.git     # or with ssh

Using named constructors

The general usage of a Backbone class is to use the .extend method providing an .initialize method.

var MyView = Backbone.View.extend({
  initialize: function () {
    // Setup object.
 }