Q1:位运算符??
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators
Q2:对象运算符??
Q3:lable try...catch...finally with label ??
lable
http://www.w3school.com.cn/js/js_errors.asp
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/try...catch
with https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/with
label https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/label
Q4:函数 what、how、why ??
Q5:原型 what、how、why ??
Q6:构造函数 what、how、why ??
Q7:onblur方法 onfocus方法 ??
http://www.w3school.com.cn/jsref/dom_obj_event.asp
Q8:2:"blog.163.com"
怎么获得的??
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>match</title>
</head>
<body>
<script>
var url = 'http://blog.163.com/album?id=1#comment';
var arr = url.match(/(https?:)\/\/([^\/]+)(\/[^\?]*)?(\?[^#]*)?(#.*)?/);
// var arr = url.match(/(https?:)\/\/([^\/]+)([^\?]*)([^#]*)(.*)/);
console.log(arr);
</script>
</body>
</html>```
Q9:将<script>放在`<div id="containr"></div>`下才行,为什么??
![报错
将<script>放在`<div id="containr"></div>`下才行](https://img.haomeiwen.com/i316258/91d12850d9ba32dc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>pratise</title>
<script type="text/javascript">
var container = document.getElementById('container');
var html = '<label>网址:</label><input placeholder="以http://起始">';
html = html.replace(/[<>]/g, function(m0){
switch(m0){
case '<':
return '<';
case '>':
return '>';
}
});
console.log(html);
container.innerHTML = html;
</script>
</head>
<body>
<div id="container"></div>
</body>
</html>
~~Q10: addEventListener ??~~
http://www.runoob.com/jsref/met-element-addeventlistener.html
https://developer.mozilla.org/zh-CN/docs/Web/API/EventTarget/addEventListener#Why_use_addEventListener.3F
~~Q11: innerText ??~~
http://www.phpweblog.net/kiyone/archive/2007/05/17/1206.html
~~Q12: \不能去掉,即使\后空格也不行,否则报错,那么反斜线在这里的作用是什么??~~
换行
![报错](https://img.haomeiwen.com/i316258/3d20c08245ffdf40.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
var person = {name:"刘德华", age:50};
(function(){
var person = {name:"刘德华", age:30};
var func = new Function("var person = {name:'刘德华',age:10};
console.log(person.name+person.age+'岁');");
func();
})();```
Q13:
思考题:对象方法中定义的子函数,子函数执行时this指向哪里?
三个问题:
以下代码中打印的this是个什么对象?
这段代码能否实现使myNumber.value加1的功能?
在不放弃helper函数的前提下,有哪些修改方法可以实现正确的功能?
var myNumber = {
value: 1,
add: function(i){
var helper = function(i){
console.log(this);
this.value += i;
}
helper(i);
}
}
myNumber.add(1);```
Q: 方法一中 console.log(myNumber.add(1));返回undefined,为什么不是2??
//方法一:可以把helper调整为方法函数,这样helper就可以正确引用myNumber为this了
var myNumber = {
value:1,
helper:function(i) {
console.log(this); //Object {value: 1, helper: function, add: function}
this.value +=i;
},
add: function(i) {
this.helper(i);
}
}
console.log(myNumber.add(1)); // undefined ??
//方法二:使用闭包
var myNumber = {
value: 1,
add: function(i){
var thisnew = this;
// 构建闭包
var helper = function(i){
console.log(thisnew); // Object {value: 1, add: function}
thisnew.value += i;
}
helper(i);
}
}
console.log(myNumber.add(1)); // undefined ??
//方法三:使用apply(call)调用模式,将当前helper方法借用给myNumber对象使用,这样this指向的就是myNumber对象
var myNumber = {
value: 1,
add: function(i){
var helper = function(i){
console.log(this);
this.value += i;
}
// myNumber对象借用helper方法,helper中的this将指向myNumber对象
helper.apply(myNumber,[i]); //apply方法
helper.call(myNumber,i); //call方法
}
}
//方法4,最笨的一种,针对这个题目只要不用this.value改成myNumber.value就可以了
var myNumber = {
value: 1,
add: function(i){
var helper = function(i);
console.log(this);
myNumber.value += i;
}
helper(i);
}
}
myNumber.add(1);```
Q:
Q:
网友评论