Created
August 11, 2012 18:23
-
-
Save mattijs/3326180 to your computer and use it in GitHub Desktop.
Backbone + Underscore + Request setups
This file contains hidden or 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
/** | |
* Faulty test setup. | |
* | |
* Underscore recognizes the `foo_string` as an Object and | |
* the Backbone Model refuses to set the model value in the | |
* last case. | |
*/ | |
var _ = require('underscore'); | |
var Backbone = require('backbone'); | |
var request = require('request'); | |
// Base values | |
var foo_string = 'bar'; | |
var foo_object = { bar: "baz" }; | |
var foo_model = new Backbone.Model(); | |
// String tests | |
console.log('// String test'); | |
console.log('String is a String: ' + _.isString(foo_string)); | |
console.log('String is an Object: ' + _.isObject(foo_string)); | |
console.log(); | |
// Object tests | |
console.log('// Object test'); | |
console.log('Object is an Object: ' + _.isObject(foo_object)); | |
console.log('Object is a String: ' + _.isString(foo_object)); | |
console.log(); | |
// Model tests | |
console.log('// Model test'); | |
foo_model.set({ 'foo': 'bar' }); | |
console.log('Model value for foo set to: ' + foo_model.get('foo')); | |
foo_model.set('bar', 'baz'); | |
console.log('Model value for bar set to: ' + foo_model.get('bar')); |
This file contains hidden or 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
/** | |
* Passing test setup. | |
* | |
* Everything checks out in this setup, without | |
* the request module loaded. | |
*/ | |
var _ = require('underscore'); | |
var Backbone = require('backbone'); | |
// Base values | |
var foo_string = 'bar'; | |
var foo_object = { bar: "baz" }; | |
var foo_model = new Backbone.Model(); | |
// String tests | |
console.log('// String test'); | |
console.log('String is a String: ' + _.isString(foo_string)); | |
console.log('String is an Object: ' + _.isObject(foo_string)); | |
console.log(); | |
// Object tests | |
console.log('// Object test'); | |
console.log('Object is an Object: ' + _.isObject(foo_object)); | |
console.log('Object is a String: ' + _.isString(foo_object)); | |
console.log(); | |
// Model tests | |
console.log('// Model test'); | |
foo_model.set({ 'foo': 'bar' }); | |
console.log('Model value for foo set to: ' + foo_model.get('foo')); | |
foo_model.set('bar', 'baz'); | |
console.log('Model value for bar set to: ' + foo_model.get('bar')); |
This file contains hidden or 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
/** | |
* Passing test setup. | |
* | |
* Everything checks out in this setup. The only | |
* thing that changed is the location of the require | |
* statement for the request module. | |
*/ | |
var _ = require('underscore'); | |
var Backbone = require('backbone'); | |
// Base values | |
var foo_string = 'bar'; | |
var foo_object = { bar: "baz" }; | |
var foo_model = new Backbone.Model(); | |
// !! Request require moved passed Model creation. | |
var request = require('request'); | |
// String tests | |
console.log('// String test'); | |
console.log('String is a String: ' + _.isString(foo_string)); | |
console.log('String is an Object: ' + _.isObject(foo_string)); | |
console.log(); | |
// Object tests | |
console.log('// Object test'); | |
console.log('Object is an Object: ' + _.isObject(foo_object)); | |
console.log('Object is a String: ' + _.isString(foo_object)); | |
console.log(); | |
// Model tests | |
console.log('// Model test'); | |
foo_model.set({ 'foo': 'bar' }); | |
console.log('Model value for foo set to: ' + foo_model.get('foo')); | |
foo_model.set('bar', 'baz'); | |
console.log('Model value for bar set to: ' + foo_model.get('bar')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment