Skip to content

Instantly share code, notes, and snippets.

* test
* test
* second level
* second level
* third level
* third level
// Exercise 2 - Closures
// Wrap the following code in a closure and export only the "countdown" function.
// Code
(function () {
var index;
function log() {
console.log(index);
}
// Exercise 2 - Closures
// Wrap the following code in a closure and export only the "countdown" function.
// Code
(function (container) {
var index;
function log() {
console.log(index);
}
//OO Style
var Car = function () {
var self = {};
self.maker;
self.color;
self.log = function () {
console.log("Im a " + self.color + " " + self.maker);
};
//Consider this as part of a bigger classlike object
.bind('NewButtonClicked.BaseEditWidget.FahrerController', function (event, data) {
if (isInEditMode()) {
dialogWidget.question('Änderungen verwerfen?', 'Sie befinden sich im Bearbeitungsmodus. Möchten Sie den Bearbeitungsmodus beenden und ggf. getätigte Änderungen verwerfen?').done(function () {
//This code is duplicate because I dont want to clutter my class like object with too many
//tiny trivial methods. However, wrapping the snippet in a function just inside this handler
//should be fine or not? (Look at the refactoring at the bottom)
currentEntity = createNewEntity();
fahrerEditWidget.loadFahrer(currentEntity);
fahrerEditWidget.enable();
// 1. Write a class to support the following code:
// 2. Add a getName() method to all Person objects, that outputs
// the persons name.
var Person = function(name){
this.name = name;
};
Person.prototype.getName = function(){
Function.prototype.cache = function () {
if (this.cache === undefined){
this.cache = {};
}
if (this.cache[arguments[0]] !== undefined){
console.log("using the cache");
return this.cache[arguments[0]]; //I wonder why this works even for object arguments (e.g. {test: 3})? Implicity converted to string?
}
else{
@cburgdorf
cburgdorf / gist:894975
Created March 30, 2011 18:41
comparing functional syntax between C# and F#
//Functional Style in C#
public void PrintSquares (string message, int n1, int n2)
{
Func<int,int> square = x => x * x;
Action<int> printSquare = (x) => Console.WriteLine(string.Format("{0} {1}: {2}", message, x, square(x)));
printSquare(n1);
printSquare(n2);
}
@cburgdorf
cburgdorf / gist:895116
Created March 30, 2011 19:27
Extension Method to Create a New Tuple based on an existing one and copy over the first Item
//Extension Method to Create a New Tuple based on an existing one and copy over the first Item
// C#
public static Tuple<T1, T2> WithItem2<T1, T2>(this Tuple<T1, T2> tuple, T2 newItem2)
{
return Tuple.Create(tuple.Item1, newItem2);
}
//Same Method in F#
@cburgdorf
cburgdorf / gist:1033292
Created June 18, 2011 17:22
Configuration parsing is fun
/// <summary>
/// Splits up an configuration string and returns an Dictionary<string, string>
/// (e.g. "CommandName='FilesOnly'; Directory='C:\\Test\\'" becomes
/// new Dictionary<string, string>
/// {
/// {"commandname", "filesonly"},
/// {"directory", "c:\\test\\"}
/// })
/// </summary>
private Dictionary<string, string> ParseString(string configurationString)