Skip to content

Instantly share code, notes, and snippets.

View brikis98's full-sized avatar

Yevgeniy Brikman brikis98

View GitHub Profile
@brikis98
brikis98 / ClassDeclaration.js
Created June 12, 2011 02:44
JavaScript class declaration
function LinkedInClient(keys, tokens) {
// ...
};
LinkedInClient.prototype.getRequestToken = function(redirectUrl, callback) {
// ...
};
LinkedInClient.prototype.getAccessToken = function(oauthVerifier, callback) {
// ...
@brikis98
brikis98 / ClassDeclarationWithInheritance.js
Created June 12, 2011 03:09
JavaScript class declaration with inheritance
LinkedInClient.prototype = new BaseClient();
LinkedInClient.prototype.constructor = LinkedInClient;
function LinkedInClient(keys, tokens) {
// ...
};
LinkedInClient.prototype.getRequestToken = function(redirectUrl, callback) {
LinkedInClient.prototype.getRequestToken.call(this, redirectUrl, callback); // call method of "super" class
};
@brikis98
brikis98 / ClassDeclarationWithInheritance.coffee
Created June 12, 2011 03:15
CoffeeScript class declaration with Inheritance
class LinkedInClient extends BaseClient
constructor: (keys, tokens) ->
# ...
getRequestToken: (redirectUrl, callback) ->
super(redirectUrl, callback) # call method of "super" class
getAccessToken: (oauthVerifier, callback) ->
# ...
@brikis98
brikis98 / FunctionDeclaration.coffee
Created June 12, 2011 03:26
JavaScript vs. CoffeeScript function declaration
getRequestToken = (redirectUrl, callback) ->
# Do something
@brikis98
brikis98 / SettingFields.coffee
Created June 12, 2011 03:37
JavaScript vs. CoffeeScript setting fields
constructor: (@keys, @tokens) ->
# Do something else - this.keys and this.tokens are automatically set!
@brikis98
brikis98 / ThisAndCallbacks.js
Created June 12, 2011 03:45
JavaScript this keyword and callbacks
this.foo = 'bar';
console.log(this.foo); // prints 'bar'
$('#myButton').click(function(event) {
console.log(this.foo); // prints 'undefined' since it's not the same 'this'
});
@brikis98
brikis98 / ThisThatAndCallbacks.js
Created June 12, 2011 03:50
JavaScript this keyword, that, and callbacks
this.foo = 'bar';
console.log(this.foo); // prints 'bar'
var that = this; // save a reference
$('#myButton').click(function(event) {
console.log(this.foo); // prints 'undefined' since it's not the same 'this'
console.log(that.foo); // prints 'bar'
});
@brikis98
brikis98 / ThisBinding.coffee
Created June 12, 2011 03:53
CoffeeScript this binding
@foo = 'bar'
console.log(@foo) # prints 'bar'
$('#myButton').click (event) =>
console.log(@foo) # prints 'bar'
@brikis98
brikis98 / StringInterpolation.js
Created June 12, 2011 04:02
JavaScript's (lack of) string interpolation
var url = LinkedInClient.baseUrl + "/v1/groups/" + id + "/posts:(" + LinkedInClient.groupFields.join(',') + ")?count=10";
this.oauth.getProtectedResource(url, 'GET', this.tokens.oauthAccessToken, this.tokens.oauthAccessTokenSecret, function(error, data, response) {
// ...
});
@brikis98
brikis98 / StringInterpolation.coffee
Created June 12, 2011 04:04
CoffeeScript string interpolation
url = "#{LinkedInClient.baseUrl}/v1/groups/#{id}/posts:(#{LinkedInClient.groupFields.join(',')})?count=10"
@oauth.getProtectedResource url, 'GET', @tokens.oauthAccessToken, @tokens.oauthAccessTokenSecret, (error, data, response) =>
# ...