Created
August 12, 2012 16:31
-
-
Save meritt/3332718 to your computer and use it in GitHub Desktop.
Пример работы компилятора CS -> JS
This file contains 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
options = {} unless options? | |
options.type = type if type? |
This file contains 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
if (typeof options === "undefined" || options === null) { | |
var options = {}; | |
} | |
if (typeof type !== "undefined" && type !== null) { | |
options.type = type; | |
} |
This file contains 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
options = {url} | |
options = | |
url: 'link' | |
text: 'description' | |
show: false |
This file contains 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 options = { | |
url: url | |
}; | |
var options = { | |
url: 'link', | |
text: 'description', | |
show: false | |
}; |
This file contains 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
do -> | |
parse = (body) -> JSON.parse body | |
request = (url, fn = ->) -> | |
xhr {url}, (error, request, body) -> fn.call @, parse body |
This file contains 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() { | |
var parse, request; | |
parse = function(body) { | |
return JSON.parse(body); | |
}; | |
request = function(url, fn) { | |
if (fn == null) { | |
fn = function() {}; | |
} | |
xhr({url: url}, function(error, request, body) { | |
fn.call(this, parse(body)); | |
}); | |
}; | |
})(); |
This file contains 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
do (tumblr) -> | |
@debug = (text) -> console.log text | |
@periodical = (message) -> | |
setTimeout (=> @debug message), 1000 |
This file contains 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(tumblr) { | |
this.debug = function(text) { | |
return console.log(text); | |
}; | |
this.periodical = function(message) { | |
var _this = this; | |
setTimeout(function() { | |
_this.debug(message); | |
}, 1000); | |
}; | |
})(tumblr); |
This file contains 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
do (tumblr) -> | |
@posts = (options, fn) -> | |
[fn, options] = [options, null] if typeof options is 'function' | |
request options, fn | |
alias = (self, type) -> | |
self[type] = (options, fn) -> @posts options, fn | |
alias tumblr, type for type in ['text', 'quote', 'link', 'answer', 'video', 'audio', 'photo'] |
This file contains 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(tumblr) { | |
var alias, type, _i, _len, _ref; | |
this.posts = function(options, fn) { | |
var _ref; | |
if (typeof options === 'function') { | |
_ref = [options, null], fn = _ref[0], options = _ref[1]; | |
} | |
request(options, fn); | |
}; | |
alias = function(self, type) { | |
self[type] = function(options, fn) { | |
this.posts(options, fn); | |
}; | |
}; | |
_ref = ['text', 'quote', 'link', 'answer', 'video', 'audio', 'photo']; | |
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
type = _ref[_i]; | |
alias(tumblr, type); | |
} | |
})(tumblr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment