This file contains hidden or 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
Let's say you have the following type definition in C#: | |
public class Thing | |
{ | |
public int Id { get; set; } | |
public string FirstName { get; set; } | |
public string ISBN { get; set; } | |
public DateTime ReleaseDate { get; set; } | |
} |
This file contains hidden or 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 Cat(name) { | |
var voice = "Meow"; | |
this.name = name; | |
this.say = function () { | |
return voice; | |
} | |
} | |
Cat.prototype.eat = function () { | |
return "Eating"; |
This file contains hidden or 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 Book = (function () { | |
// private static field | |
var numOfBooks = 0; | |
// private static method | |
function checkIsbn(isbn) { | |
if (isbn.length != 10 && isbn.length != 13) throw new Error("isbn is not valid!"); | |
} | |
function Book(isbn, title) { | |
checkIsbn(isbn); |
This file contains hidden or 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 Logger = { | |
enabled: true, | |
log: function (logText) { | |
if (!this.enabled) return; | |
if (console && console.log) console.log(logText); | |
else alert(logText); | |
} | |
} | |
Or |
This file contains hidden or 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
//or var dog = {}; | |
//or var dog = new MyDogType(); | |
//or var newDog = Object.create( null ); | |
var dog = new object(); | |
dog.name = "Scooby"; | |
dog.owner = {}; | |
dog.owner.name = "Mike"; | |
dog.bark = function () { | |
return "Woof"; | |
}; |
This file contains hidden or 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 Car( model, year, miles ) { | |
this.model = model; | |
this.year = year; | |
this.miles = miles; | |
// toString is redefined for each of the new objects created using the Car constructor | |
// its not so optimal. | |
this.toString = function () { | |
return this.model + " has done " + this.miles + " miles"; |
This file contains hidden or 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 myNamespace = (function () { | |
var myPrivateVar, myPrivateMethod; | |
// A private counter variable | |
myPrivateVar = 0; | |
// A private function which logs any arguments | |
myPrivateMethod = function( foo ) { | |
console.log( foo ); |
This file contains hidden or 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 myRevealingModule = function () { | |
var privateVar = "Ben Cherry", | |
publicVar = "Hey there!"; | |
function privateFunction() { | |
console.log( "Name:" + privateVar ); | |
} | |
function publicSetName( strName ) { |
This file contains hidden or 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
public class Resource : IDisposable | |
{ | |
private IntPtr nativeResource = Marshal.AllocHGlobal(100); | |
private AnotherResource managedResource = new AnotherResource(); | |
// Dispose() calls Dispose(true) | |
public void Dispose() | |
{ | |
Dispose(true); | |
GC.SuppressFinalize(this); |
This file contains hidden or 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
using System; | |
using System.Web; | |
using System.ComponentModel; | |
public static class EventBroker | |
{ | |
private static object EventsKey = new object(); | |
public static void Subscribe<TType>(this HttpContextBase source, object key, EventHandler<TType> value) | |
where TType : EventArgs |
OlderNewer