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
// 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); | |
} |
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
// 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); | |
} |
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
//OO Style | |
var Car = function () { | |
var self = {}; | |
self.maker; | |
self.color; | |
self.log = function () { | |
console.log("Im a " + self.color + " " + self.maker); | |
}; |
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
// 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(){ |
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.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{ |
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
//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(); |
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
//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); | |
} |
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
//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# |
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
/// <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) |
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
Rx.Observable.prototype.WrapAs = function (propertyName) { | |
return this.Select(function (x) { | |
var temp = {}; | |
temp[propertyName] = x; | |
return temp; | |
}); | |
}; | |
Rx.Observable.prototype.AppendAs = function (propertyName, data) { | |
return this.Select(function (x) { |
OlderNewer