## Understanding Bind in JavaScript

01-12-2014

var papa = {
name: "li gang",
son: function() {
return this.name;
}
};
alert( papa.son() );


var son = papa.son;
alert( son() );


alert( son.call(papa) );


son = son.bind( papa );
alert( son() );


function erGouZi() {
return this.name;
}


erGouZi = erGouZi.bind( papa );
alert( erGouZi() );


erGouZi = function() {
var prefix = arguments[0] || "";
return prefix + this.name;
}
erGouZi = erGouZi.bind( papa, "great " );
alert( erGouZi() );


Copied from here

21-11-2014

copied from here

## JavaScript : 實作柯里化(Currying)與部份調用

將多參數函數轉換為一系列單參數函數。它描述了轉換過程，而不是轉換函數的調用。



將多參數函數轉換為一個參數更少的多參數函數，其值為提前提供的省略參數的值。



var linearFunction = function(a, b, x) {
return a * x + b;
}


## Deferred in jQuery

21-11-2014

Copied from here

jQuery的开发速度很快，几乎每半年一个大版本，每两个月一个小版本。

## Convert JavaScript object To String

21-11-2014
function objToString (obj) {
var str = '';
for (var p in obj) {
if (obj.hasOwnProperty(p)) {
str += p + '::' + obj[p] + '\n';
}
}
return str;
}


or

JSON.stringify(obj);


Written with StackEdit.

## Principal End of One2One Map in EntityFramework

21-11-2014

##What does principal end of an association means?

In one-to-one relation one end must be principal and second end must be dependent. Principal end is the one which will be inserted first and which can exist without the dependent one. Dependent end is the one which must be inserted after the principal because it has foreign key to the principal.

##How to config in FluentAPI? Say we have one to one User and UserProfile entities, and the User is principal, UserProfile is dependant.

class User{
UserProfile Profile { get;set; }
//...
}

class UserProfile{
User User{ get;set; }
//...
}


Then the fluentAPI configuration will be:

modelBuilder.Entity<User>().HasRequired(u => u.Profile).WithRequiredPrincipal(p => p.User);
`

Written with StackEdit.