Skip to content

Instantly share code, notes, and snippets.

### The current context
The value of `this` in a javascript function call depends on the *execution context* of the function. If we take the above execution of `Simple()` but exclude the new keyword,
`this` would refer to the global object and the `name` property would be added to that object. In a browser the global object is `window`, so in this example, name would be a property of
the `window` object:
``` javascript
Simple();
console.log(window.name);
=> "Adam"
@stantona
stantona / gist:4197676
Created December 3, 2012 20:15
Coffeescript inheritance.
__extends = function(child, parent) {
__hasProp = {}.hasOwnProperty
for (var key in parent) {
if (__hasProp.call(parent, key))
child[key] = parent[key];
}
function ctor() {
this.constructor = child;
@stantona
stantona / covo_card.haml
Created September 20, 2012 17:26
check for cover image
%header{class: topic.cover_image? ? 'coverimage' : ''}
-if topic.cover_image?
%figure.img-canvas-small
=image_tag(comment.topic.cover_image)
-# I want this execute seperately, but nested in header
%article
%h2
-if comment.conversation.subject?
%a.title{ href: conversation_path(comment.conversation, anchor: comment.id.to_s), 'data-pjax' => '#container' }
// specify it under conversation style
.conversation {
header {
padding-top: 12px;
padding-bottom: 12px;
}
}
// specify it explicitly
header.single-line {