String.method ("Trim", function () {
Return This.replace (/^\s+|\s+$/g, "");
})
"Neat". Trim ();//neat
Closed Bag
var quo = function (status) {
return{
Get_status:function () {
return status;
}
}
}
var myquo = new Quo ("amazed");
Myquo.get_status ();//amazed
Closure Classic Example Fragment
for (Var i=0;i<lis.length;i++) {
Lis.onclick=function (i) {
return function () {
alert (i);
};
} (i);
}
Apply
Function.method ("Curry", function () {
var slice=array.prototype.slice,
args = slice.apply (arguments),
That's = this;
return function () {
Return that.apply (null,args.contact (arguments));
}
})
Memory recursion
var memoization = function (memo,usefn) {//abstract
var fn = function (n) {
var result = Memo[n];
if (typeof result!== ' number ') {
Result=usefn (Fn,n);
Memo[n]=result;
}
return result;
};
return FN;
};
var factorial= memoization ([0,1],function (Fn,n) {//recursive form
RETURN fn (n-1) *n
});
Factorial (5)//120
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service