Tuesday, November 25, 2008

LINQ Query

Almonst every generic collection provided by the .NET Framework implements IEumerable. .NET controls support data binding to any IEnumerable collection.
LINQ query return results is type IEumerable T is determined by the object type of the select clause

Saturday, November 8, 2008

HTTP ready state:

0 uninitialized
1 loading
2 loaded
3 interactive
4 complete

Useful HTTP status:

200 OK
201 Created
204 No Content
205 Reset Content
206 Partial Content
400 Bad Request
401 Unauthorized
404 Not Found
405 Method Not Allowed
403 Forbidden
406 Not Acceptable
407 Proxy Authentication Required
408 Request Timeout
411 Length Required
413 Requested Entity Too Large
414 Requested URL Too Long
415 Unsupported Media Type
500 Internal Server Error
502 Bad Gateway
501Not Implemented
503 Service Unavailable
504 Gateway Timeout
505 HTTP Version Not Supported

Thursday, November 6, 2008

Inheritance using Closures and Prototypes

example for Closure:

function Car(name)
{
this.Name = name;
this.Drive = Drive;
}
function Drive(){}

function SuperCar(name)
{
//implement closure inheritance
this.inheritsFrom = Car;
this.inheritsFrom(name);
//add new method
this.Fly = Fly;
}
function Fly(){}

example for Prototyping:

function Car(name)
{
this.Name = name;
}
Car.prototype.Drive = function()
{
document.write("My Name is " + this.Name + " and I am driving
");
}
SuperCar.prototype = new Car();
SuperCar.prototype.constructor = SuperCar();
SuperCar.prototype.Fly = function()
{
document.write("My Name is " + this.Name + " and I am flying
");
}
function SuperCar(name)
{
Car.call(this,name);
}

Function as variable

In Javascript, function is first-class object, which is mean that a function is regarded as a data type which the value can be saved in local vaiables, passed as paramenters and assigned.

Keep in mind the javasript objects is understanding as collection (key value)pairs.

JavaScript doesn't support the notion of private memebers as C#, but we can simulate the functionality by ising variables inside the function. by declared the variable using keyword "var" instead of "this", thus acting like private members. Variables can, however, be accessed by closure functions.

Tuesday, November 4, 2008

JavaScript Object (base) Oriented Programming

allowing runtime type reflection
allowing OOP advantage--- classes, interfaces, inheritance , emulate c# as much as possible.

Reflection comes from the important class -- Type

JavaScript Functions includes arguments, constructor and prototype

call and apply methods apply to function

Array.addRange() ---- is add item to array

Array.addRange() ---- is add item to array
var a= [1,2];
var b= [3,4];
Array.addRange(a, b) ---- add b array to a
for(var i in a) ---- the result will be 1,2,3,4

Array.clone() --- is shallow copy : only copy the reference but the objects being referenced are not copied
array.push --- push the item on the top of the stack
array.pop -- pop method pops up the item at the top of the stack

Sunday, November 2, 2008

Client Delegates

Function.createDelegate(),

Steps create client delegate:

1) create client delegate by using Function.createDelegate(this, functionName)

2) add the new delegate into $addHandler(this, newDelegate)

3) access the window object, write the function

example:
function pageLoad() {
var clickDelegate = Function.createDelegate(this,onButtonClick);
$addHandler($get('btnTest'),'click',clickDelegate);
}
function onButtonClick()
{
alert(String.format("this code is funning on {0} {1}", Sys.Browser.name, Sys.Browser.version));
}

Client-page lifecycle

Sys.Application object lifecycle:
init, load, unload
1) When browser starts: Sys.Application object start initializing the MS Ajax library's runtime. firle the init event, initialized and instantiated all the client components.

2)Sys.Applicaton fires the load event.

3) when user mavigates away from the page or reloads page, the unload event of the window object intercepted by Sys.Application