|
@@ -0,0 +1,176 @@
|
|
|
+<!DOCTYPE html>
|
|
|
+<html lang="en">
|
|
|
+
|
|
|
+<head>
|
|
|
+ <meta charset="UTF-8">
|
|
|
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
+ <title>Document</title>
|
|
|
+</head>
|
|
|
+
|
|
|
+<body>
|
|
|
+ <div id="div">hello</div>
|
|
|
+ <script>
|
|
|
+ // var x = 10;
|
|
|
+ // function test() {
|
|
|
+ // this.x = 20
|
|
|
+ // console.log(this.x)//20
|
|
|
+ // }
|
|
|
+ // test()
|
|
|
+
|
|
|
+
|
|
|
+ // 第二题
|
|
|
+ // var name = "window"
|
|
|
+ // var obj = {
|
|
|
+ // name: "obj",
|
|
|
+ // func1: function () {
|
|
|
+ // console.log(this.name);//obj
|
|
|
+ // (function () {
|
|
|
+ // console.log(this.name)//window
|
|
|
+ // })()
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // obj.func1()
|
|
|
+
|
|
|
+ // 第三题
|
|
|
+ // var name = "the window";
|
|
|
+
|
|
|
+ // var object = {
|
|
|
+ // name: "My Object",
|
|
|
+ // getName: function () {
|
|
|
+ // return this.name;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // console.log(object.getName());//My Object
|
|
|
+ // console.log((object.getName)());//My Object
|
|
|
+ // console.log((object.getName = object.getName)());//the window
|
|
|
+
|
|
|
+ // var a = 20;
|
|
|
+ // var obj = {
|
|
|
+ // a:10,
|
|
|
+ // foo:function(){
|
|
|
+ // console.log(this.a)
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // (function(){
|
|
|
+ // console.log(this.a)
|
|
|
+ // }())
|
|
|
+
|
|
|
+
|
|
|
+ // var a = 1;
|
|
|
+ // if(1){}
|
|
|
+ // var foo = obj.foo;
|
|
|
+ // obj.foo();
|
|
|
+ // foo();
|
|
|
+
|
|
|
+ // var foo = function(){
|
|
|
+ // console.log(123);
|
|
|
+ // }
|
|
|
+
|
|
|
+ // (function(){console.log(123);}())
|
|
|
+
|
|
|
+ // (function(){
|
|
|
+ // console.log(123);
|
|
|
+ // }());
|
|
|
+
|
|
|
+ // (function(){
|
|
|
+ // console.log(123);
|
|
|
+ // })();
|
|
|
+
|
|
|
+ // 第四题
|
|
|
+ // document.getElementById("div").onclick = function(){
|
|
|
+ // console.log(this.innerText);
|
|
|
+ // }
|
|
|
+
|
|
|
+ // 第五题
|
|
|
+ // var name = "window"
|
|
|
+ // var obj = {
|
|
|
+ // name: "obj"
|
|
|
+ // }
|
|
|
+ // window.setInterval(function () {
|
|
|
+ // console.log(this.name)
|
|
|
+ // }, 300)
|
|
|
+
|
|
|
+ // window.setInterval(function () {
|
|
|
+ // console.log(this.name)
|
|
|
+ // }.call(obj), 300)
|
|
|
+
|
|
|
+ // function foo(){
|
|
|
+ // console.log("hello");
|
|
|
+ // }
|
|
|
+ // console.log(foo());
|
|
|
+
|
|
|
+ // setInterval(foo.call(window),1000)
|
|
|
+
|
|
|
+ // 第六题
|
|
|
+ // function foo() {
|
|
|
+ // //补全此处代码实现每隔一秒输出 hello world
|
|
|
+ // // console.log("hello world");
|
|
|
+ // return function(){
|
|
|
+ // console.log("hello world");
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // window.setInterval(foo(), 1000);
|
|
|
+
|
|
|
+ // function foo() {
|
|
|
+ //补全此处代码实现每隔一秒 输出累加的值 1 2 3 4 5 6 ...
|
|
|
+ // }
|
|
|
+ // window.setInterval(foo(), 1000);
|
|
|
+
|
|
|
+ // 7、补全下列代码实现 1+2+3+4 (this 不能指向window)
|
|
|
+ // function add(c, d) {
|
|
|
+ // return this.a + this.b + c + d;
|
|
|
+ // }
|
|
|
+
|
|
|
+ /*
|
|
|
+ 在此补全代码 以两种以上方法实现
|
|
|
+ */
|
|
|
+ // var a = 1;
|
|
|
+ // var b = 2;
|
|
|
+ // var obj = {
|
|
|
+ // a:1,
|
|
|
+ // b:2
|
|
|
+ // }
|
|
|
+ // var res = add(3,4)
|
|
|
+ // var res = add.call(obj,3,4);
|
|
|
+ // console.log(res);
|
|
|
+
|
|
|
+ // 第八题
|
|
|
+ // function f() {
|
|
|
+ // return this.a;
|
|
|
+ // }
|
|
|
+ // // bind不可以对同一个函数绑定多次 如果绑定多次的话以第一次为准
|
|
|
+ // var g = f.bind({ a: "azerty" });
|
|
|
+ // console.log(g());//azerty
|
|
|
+
|
|
|
+ // var h = g.bind({ a: 'yoo' });
|
|
|
+ // console.log(h());//azerty
|
|
|
+
|
|
|
+ // var o = {
|
|
|
+ // a: 'loveCoding',
|
|
|
+ // f: function(){
|
|
|
+ // return this.a
|
|
|
+ // },
|
|
|
+ // g: g,
|
|
|
+ // h: h
|
|
|
+ // };
|
|
|
+ // console.log(o.f(), o.g(), o.h());//loveCoding azerty azerty
|
|
|
+
|
|
|
+ // var a = "hello"
|
|
|
+ // function foo(i){
|
|
|
+ // console.log(this.a+i);//10world
|
|
|
+ // }
|
|
|
+ // var obj = {
|
|
|
+ // a:10
|
|
|
+ // }
|
|
|
+ // foo()
|
|
|
+ // foo.call(obj,"world");
|
|
|
+ // foo.apply(obj,["world"]);
|
|
|
+ // var foo2 = foo.bind(obj,"world");
|
|
|
+ // foo2()
|
|
|
+
|
|
|
+ </script>
|
|
|
+</body>
|
|
|
+
|
|
|
+</html>
|