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
function laugh() | |
{ | |
return | |
{ | |
haha: "ha!" | |
}; | |
} | |
laugh(); | |
// returns undefined |
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
// It?s treated like: var x = (y = 1); thus, ?y=1? creates an auto-global since there?s no binding ?var? statement for it. then that value gets copied into properly defined local var ?x?. | |
(function(){ | |
var x = y = 1; | |
})(); | |
alert(x); // undefined | |
alert(y); // 1 -- oops, auto-global! |
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
// In JavaScript, undefined is nothing but a global variable name without a default value. Therefore, its primitive value is undefined. You can change the value of undefined: | |
var a = {}; | |
a.b === undefined; // true because property b is not set | |
undefined = 42; | |
a.b === undefined; // false | |
// Due to the mutability of undefined, it is generally a better idea to check for undefined-ness through typeof: | |
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
# http://coffeescriptcookbook.com/chapters/jquery/callback-bindings-jquery | |
# By using the fat arrow (=>) instead of the normal arrow (->) the function gets automatically bound to the object and can access the @-variable. | |
$ -> | |
class Basket | |
constructor: () -> | |
@products = [] | |
$('.product').click (event) => |
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
# http://coffeescriptcookbook.com/chapters/syntax/embedding_javascript | |
`function greet(name) { | |
return "Hello "+name; | |
}` | |
# Back to CoffeeScript | |
greet "Coffee" | |
# => "Hello Coffee" |
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
# -= styling =- | |
# li label.over | |
# margin-top: 16px | |
# margin-left: 9px | |
# color: #777 | |
# input[type="text"]:active, input[type="password"]:active | |
# color: black |
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
adc = adc or {} | |
class adc.particle | |
bounds: null | |
constructor: -> | |
@x = Math.random() * @bounds.x2 | |
@y = Math.random() * @bounds.y2 | |
class adc.particleFoo extends adc.particle |
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
# // http://arcturo.github.com/library/coffeescript/03_classes.html | |
# // We're going to define a class called Module that we can inherit from for mixin support. Module will have two static functions, @extend() and @include() which we can use for extending the class with static and instance properties respectively. | |
moduleKeywords = ['extended', 'included'] | |
class Module | |
@extend: (obj) -> | |
for key, value of obj when key not in moduleKeywords | |
@[key] = value |
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
describe('built-in matchers', function() { | |
describe('toBeTruthy', function() { | |
it('passes if subject is true', function() { | |
expect(true).toBeTruthy(); | |
expect(false).not.toBeTruthy(); | |
}); | |
}); | |
describe('toBeFalsy', function() { | |
it('passes if subject is false', function() { |
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
var parser = document.createElement('a'); | |
parser.href = "http://example.com:3000/pathname/?search=test#hash"; | |
parser.protocol; // => "http:" | |
parser.hostname; // => "example.com" | |
parser.port; // => "3000" | |
parser.pathname; // => "/pathname/" | |
parser.search; // => "?search=test" | |
parser.hash; // => "#hash" | |
parser.host; // => "example.com:3000" |