Home Manual ReferenceGraphs Source Repository
import Utils from 'backbone-es6/src/Utils.js'
public class | source

Utils

Provides static utility functions.

Proxy Backbone class methods to Underscore functions, wrapping the model's attributes object or collection's models array behind the scenes.

Function#apply can be slow so we use the method's arg count, if we know it.

Example:

collection.filter(function(model) { return model.get('age') > 10 });
collection.each(this.addView);

Static Method Summary

Static Public Methods
public static

addUnderscoreMethods(Class: Class, methods: object, attribute: string)

Adds Underscore methods if they exist from keys of the methods hash to Class running against the variable defined by attribute

public static

isModel(unknown: *): boolean

Method for checking whether an unknown variable is an instance of Backbone.Model.

public static

isNullOrUndef(unknown: *): boolean

Method for checking whether a variable is undefined or null.

public static

Throw an error when a URL is needed, and none is supplied.

public static

wrapError(model: Model | Collection, options: object)

Wrap an optional error callback with a fallback error event.

Static Public Methods

public static addUnderscoreMethods(Class: Class, methods: object, attribute: string) source

Adds Underscore methods if they exist from keys of the methods hash to Class running against the variable defined by attribute

Params:

NameTypeAttributeDescription
Class Class

Class to add Underscore methods to.

methods object

Hash with keys as method names and values as argument length.

attribute string

The variable to run Underscore methods against. Often "attributes"

public static isModel(unknown: *): boolean source

Method for checking whether an unknown variable is an instance of Backbone.Model.

Params:

NameTypeAttributeDescription
unknown *

Variable to test.

Return:

boolean

public static isNullOrUndef(unknown: *): boolean source

Method for checking whether a variable is undefined or null.

Params:

NameTypeAttributeDescription
unknown *

Variable to test.

Return:

boolean

public static urlError() source

Throw an error when a URL is needed, and none is supplied.

public static wrapError(model: Model | Collection, options: object) source

Wrap an optional error callback with a fallback error event.

Params:

NameTypeAttributeDescription
model Model | Collection

Model or Collection target to construct and error callback against.

options object

Options hash to store error callback inside.