日期:2014-05-16 浏览次数:20327 次
对象化编程-------简单地去理解就是把javascript能涉及到的范围分成各种对象,对象下面再次划分对象。编程出发点多是对象,或者说基于对象。所说的对象既包含变量,网页,窗口等等
?
这边我只是简单地罗列出来部分,具体的可以参考http://www.w3school.com.cn/js/js_obj_intro.asp
?
不过我这边还是想讲一下比较流行的一道前端面试题,也是我当初来百度面试的时候问我的(题目的来源好像是方荣大侠的某个web前端研发工程师编程能力成长之路的文档里面的)
废话少说------出题:
?? ? ? ? ? ? ? ? ? ? ? “输出字符串--今天是星期几”
?
答案1:
?
var _str = ""; var _today = new Date().getDay(); if(_today == 0){ _str = "今天是星期日"; }else if(_today == 1){ _str = "今天是星期一"; }else if(_today == 2){ _str = "今天是星期二"; }else if(_today == 3){ _str = "今天是星期三"; }else if(_today == 4){ _str = "今天是星期四"; }else if(_today == 5){ _str = "今天是星期五"; }else if(_today == 6){ _str = "今天是星期六"; }
?答案2:
?
var _str ="今天是星期";
var _today=new Date().getDay(); switch(_today){ case 0: _str += "日"; break; case 1: _str += "一"; break; case 2: _str += "二"; break; case 3: _str += "三"; break; case 4: _str += "四"; break; case 5: _str += "五"; break; case 6: _str += "六"; break; }
?答案3:
?
var _arr = new Array("日","一","二","三","四","五","六"); var _today = new Date().getDay(); var _str = "今天是星期"+_arr[_today ];
?
?答案4:
?
var _str = "今天是星期"+"日一二三四五六".charAt(new Date().getDay());
?3.?
var people ={};
people.name = "steven";
people.age = 23;
people.getName = function(){
return "People's name is "+ this.name;
};
console.log(people.getName()); //People's name is steven
console.log(people.age); //23
?