日期:2014-05-16 浏览次数:20617 次
var a = 5; function runMe(a){ console.log("a = " + a);//a=? function innerRun(){ console.log("b = " + b);//b=? console.log("c = " + c);//c=? } var b = 7; innerRun(); var c = 8; } runMe(6); for ( var d = 0; d < 3; d++ ) { setTimeout(function(){ console.log("d = " + d);//d=? }, 100); }
var count = 0; for ( var i = 0; i < 4; i++ ) (function(i){ setTimeout(function(){ console.log(“i = ” + i); }, i * 200); })(i);
function Ninja(){ this.swingSword = function(){ return true; }; } Ninja.prototype.swingSword = function(){ return false; }; var ninja = new Ninja(); console.log(ninja.swingSword());//false or true?
var a = { a :0, 'b' :1, 'a' : 2, class : 2, first-name :2 };
var obj = {name : 'iteye'}; console.log(obj.age);//输出什么 console.log(obj.age.val);//这里又输出什么
function Ninja(){} var ninja = new Ninja(); var ninjaB = new ninja.constructor();//可以这样写吗
function makeNinja(name){} function makeSamurai(name, rank){} makeNinja.length//? makeSamurai.length//?
function ff(){ return 1; } function ff(x){ return 2; } function ff(x,y,z){ return 3; } console.log(ff(1));//输出?
var foo = 0; var bar = 0 function ff(){ this.foo = 1 bar = 1; car = 1; var dar = 1; } ff(); console.log("foo = " + foo); console.log("bar = " + bar); console.log("car = " + car); console.log("dar = " + dar);
function addMethod(object, name, fn){ var old = object[ name ]; object[ name ] = function(){ console.log("fn.length = " + fn.length);//输出? if ( fn.length == arguments.length ) return fn.apply( this, arguments ); else if ( typeof old === "function" ) return old.apply( this, arguments ); }; } var a = {}; addMethod(a, "find", function(){ console.log("in find()"); }); addMethod(a, "find", function(x){ console.log("in find(x)"); }); addMethod(a, "find", function(x, y){ console.log("in find(x, y)"); }); a.find();