Skip to content

Instantly share code, notes, and snippets.

View mklabs's full-sized avatar

Mickael Daniel mklabs

View GitHub Profile
var foo = 'hello';
(function() {
console.log(foo); // undefined!
var foo = foo || 'world';
})();
// override the bar prop for foo w/o affecting bim
foo.bar = 'new value';
// change the bar prop for both foo and bim
// (*if* it hasn't been overridden locally!)
Thinger.prototype.bar = 'another new value';
// we could delete foo.bar now and it would get
// the prototype value instead
// delete foo.bar;
for (var obj in myObjects) {
if (myObjects.hasOwnProperty(obj)) {
myObjects[obj].destroy();
delete myObjects[obj];
}
}
$(document).ready(function() {
var handleClick = function(e) {
var el = $(e.target);
el.attr('title', 'new title')
.width('100px');
},
bar = $('#bar')
// ideally: use a class for this
.css({
(function() {
dojo.xhrGet({
url : 'foo.php',
load : function(resp) {
if (resp && resp.foo) {
// run this important code
}
}
});
})();
(function(d, $){
d.forEach(['foo', 'bar', 'baz', 'bop'], function(c) {
$('li.' + c + ' a').attr('title', 'i am ' + c);
});
})(dojo, dojo.query);
function calculateTotal(baseTotal, tip, tax, fee) {
// convert the tip to a number using base 10;
// allow for a NaN result from parseFloat
tip = parseFloat(tip) || 0;
// don't allow a negative tip
if (tip < 0) { tip = 0; }
return baseTotal + tip + tax + fee;
}
var newArray = dojo.map(menuItems, function(item) {
var ret = item.name;
if (item.extras && item.extras.length) {
ret += '(' + item.extras.join(', ') + ')';
}
return ret;
});
var thingerDom = [], gizmoDom = [],
tpl = '<p><span class="%s">i am %s %i</span></p>',
tplFn = function(str, i) {
return tpl.replace(/%s/g, str).replace(/%i/g, i);
},
i;
for (i = 0; i <= 100; i++) {
thingerDom.push(tplFn('thinger', i));
gizmoDom.push(tplFn('gizmo', i));
<ol class="action_menu">
<?php if ($User->IsLoggedIn() && $User->CanPublish()
&& $User->Articles->count() < $App->max_articles) { ?>
<li><a href="/publish">Publish New Article</a></li>
<?php } ?>
...
</ol>