Skip to content

Instantly share code, notes, and snippets.

dojo.addOnLoad(function() {
dojo.declare('Thinger', null, {
names : [ 'Pete', 'Nikolai', 'Dylan', 'Jared', 'Bill' ],
greetings : [ 'Ohai', 'Hello', 'Guten tag', 'Hola' ],
constructor : function(node, name) {
this.node = node;
name && this.forceName(name);
window.xxx = 123;
(function() { var y = xxx; var xxx = 456; alert(y); })();
$.fn.myPlugin = function(args) {
// set defaults for the plugin
var defaults = {
foo : 'bar'
},
// override those defaults with user-provided args
settings = $.extend(defaults, args),
// define functions for stuff you'll do a lot
diff --git a/src/core.js b/src/core.js
index e1a3a6d..e4b74d9 100644
--- a/src/core.js
+++ b/src/core.js
@@ -535,6 +535,8 @@ jQuery.extend({
// args is for internal usage only
each: function( object, callback, args ) {
+ if (object === undefined) { return; }
+
// instead of this
$('#myList li').each(function() {
var $li = $(this), $div = $li.find('div.content');
$li.data('contentDiv', $div);
});
// i want to do this
$('#myList li').data('contentDiv', function() { return $(this).find('div.content'); });
console.log(context.cache());
if(context.cache().recentOrders){
context.partial('templates/previous_orders/recent.mustache', PreviousOrdersView(context.cache().recentOrders), function(html) {
$('.recent_orders').html(html);
});
console.log('from cache');
}else{
var url = context.recent_orders_url(email, 5);
$.ajax({
url: url,
var foo = 'hello';
(function() {
// even tho foo is defined outside of this closure,
// the var foo declaration below initializes the variable
// inside the closure immediately -- any attempt to access
// foo inside the closure will use the local version, even
// an attempt before the var statement.
alert(foo || 'foo is not defined yet!'); // 'foo is not defined yet'
// 1: how could you rewrite the following to make it shorter?
if (foo) {
bar.doSomething(el);
} else {
bar.doSomethingElse(el);
}
(function(d, $) {
d.ready(function() {
d.connect('searchForm', 'submit', function(e) {
e.preventDefault();
var myVal = $('input', this)[0].value;
d.xhrGet({
url : 'search.php',
content : { term : myVal },
handleAs : 'json',
load : function(resp) {
dojo.provide('my.app.Strings');
(function(d) {
var baseDir = '/str/',
chain = [ baseDir + 'base.json' ];
my.app.str = {};
if (window.APP_INSTANCE) {