var i = 10;
function add(j) {
console.log(i+j);
debugger;
}
add(1);
})();
(function(){
var i = 10;
var add = new Function("j", "console.log(i+j);debugger;");
add(1);
})();
function Point(x, y){
this.x = x;
this.y = y;
}
Point.prototype.move = function(x, y) {
this.x += x;
this.y += y;
}
var p = new Point(0,0);
var circle = {x:1, y:1, r:1};
var circleMove = p.move.bind(circle, 2, 1);
circleMove();
function add(i, j){
return i+j;
}
var myNumber = {
var helper = function(){
this.value = add(this.value,this.value);
}
helper();
}
}
function add(i, j) {
var args = Array.prototype.slice.apply(arguments);
args.forEach(function(item){
console.log(item);
})
}
add(1,2,3);
function factorial(i){
if (i==0) {
return 1;
}
return i*factorial(i-1);
}
var factorial = (function(){
var count = 0;
var fac = function(i){
count++;
if (i==0) {
console.log('调用次数:' + count);
return 1;
}
return i*factorial(i-1);
}
return fac;
for(var i=0;i<=10;i++){
console.log(factorial(i));
}
//记忆函数
var factorial = (function(){
var memo = [1];
var count = 0;
var fac = function(i){
count++;
var result = memo[i];
if(typeof result === 'number'){
console.log('调用次数:' + count);
return result;
}
result = i*fac(i-1);
memo[i] = result;
return result;
}
return fac;
})();
for(var i=0;i<=10;i++){
console.log(factorial(i));
}
- curry 函数柯里化
- 把接受多个参数的函数变换成接受一个单一参数(最初函数的第一个参数)的函数,并且返回接受余下的参数而且返回结果的新函数的技术
function set_loop() {
var i =1;
setTimeout(function () {
i = i + 1;
console.log(i);
set_loop()
}