Created
June 8, 2012 06:51
-
-
Save ChrisMissal/2894063 to your computer and use it in GitHub Desktop.
Allows loading of external JavaScript files for use in on{X}
This file contains 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
(function() { | |
device.ajax( | |
{ | |
url: 'http://underscorejs.org/underscore-min.js', | |
type: 'GET', | |
headers: { | |
'Content-Type': 'text/javascript' | |
} | |
}, | |
function onSuccess(body, textStatus, response) { | |
eval(body); | |
if (_) console.log('underscore.js loaded successfully'); | |
yourCode(_); | |
}, | |
function onError(textStatus, response){ | |
console.error('error code: ', response.status); | |
}); | |
})(); | |
function yourCode(_) { | |
var stooges = [{name : 'moe', age : 40}, {name : 'larry', age : 50}, {name : 'curly', age : 60}]; | |
console.info(_.pluck(stooges, 'name')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment