|
@@ -0,0 +1,161 @@
|
|
|
+<!DOCTYPE html>
|
|
|
+<html lang="en">
|
|
|
+
|
|
|
+<head>
|
|
|
+ <meta charset="UTF-8">
|
|
|
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
|
+ <title>Document</title>
|
|
|
+</head>
|
|
|
+
|
|
|
+<body>
|
|
|
+ <script>
|
|
|
+ //1、写出下列输出结果
|
|
|
+ // var x = 10;
|
|
|
+ // function test() {
|
|
|
+ // this.x = 20
|
|
|
+ // console.log(this.x)
|
|
|
+ // }
|
|
|
+ // test()
|
|
|
+
|
|
|
+ // console.log(x)
|
|
|
+
|
|
|
+
|
|
|
+ //2、写出下列输出结果
|
|
|
+ // var name = "window"
|
|
|
+ // var obj = {
|
|
|
+ // name: "obj",
|
|
|
+ // func1: function () {
|
|
|
+ // console.log(this.name);
|
|
|
+ // (function () {
|
|
|
+ // console.log(this.name)
|
|
|
+ // })()
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // obj.func1()
|
|
|
+
|
|
|
+
|
|
|
+ //3、写出下列结果
|
|
|
+ // var name = "the window";
|
|
|
+
|
|
|
+ // var object = {
|
|
|
+ // name: "My Object",
|
|
|
+ // getName: function () {
|
|
|
+ // return this.name;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // console.log(object.getName());
|
|
|
+ // console.log((object.getName)());
|
|
|
+ // console.log((object.getName = object.getName)());
|
|
|
+
|
|
|
+ // var a = 10;
|
|
|
+ // if(a=9){
|
|
|
+ // console.log(a)
|
|
|
+ // }
|
|
|
+
|
|
|
+ // var age = 20;
|
|
|
+ // var obj = {
|
|
|
+ // age:10,
|
|
|
+ // showAge:function(){
|
|
|
+ // console.log(this.age)
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // console.log(obj.showAge);
|
|
|
+ // var fn = obj.showAge;
|
|
|
+ // // function fn2(){
|
|
|
+ // // console.log(this.age)
|
|
|
+ // // }
|
|
|
+ // fn();
|
|
|
+
|
|
|
+
|
|
|
+ //4、下列代码中当div的点击事件触发时输出的结果是?
|
|
|
+ // document.getElementById("div").onclick = function () {
|
|
|
+ // console.log(this)
|
|
|
+ // };
|
|
|
+
|
|
|
+
|
|
|
+ //5、请写出下列代码运行结果
|
|
|
+ // var name = "window"
|
|
|
+ // var obj = {
|
|
|
+ // name: "obj"
|
|
|
+ // }
|
|
|
+ // window.setInterval(function () {
|
|
|
+ // console.log(this.name)
|
|
|
+ // }, 300)
|
|
|
+ // window.setInterval(function () {
|
|
|
+ // console.log(this.name)
|
|
|
+ // }.bind(obj), 300)
|
|
|
+
|
|
|
+ //6、请补全下列代码
|
|
|
+ // function foo() {
|
|
|
+ // //补全此处代码实现每隔一秒输出 hello world
|
|
|
+ // // console.log("hello world");
|
|
|
+ // return function(){
|
|
|
+ // console.log("hello world");
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // window.setInterval(foo(), 1000);
|
|
|
+
|
|
|
+
|
|
|
+ // 7、补全下列代码实现 1+2+3+4
|
|
|
+ // function add(c, d) {
|
|
|
+ // return this.a + this.b + c + d;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // var obj = {
|
|
|
+ // a: 1,
|
|
|
+ // b: 2,
|
|
|
+ // addFun:add
|
|
|
+ // }
|
|
|
+ // console.log(obj.addFun(3,4))
|
|
|
+
|
|
|
+ /*
|
|
|
+ 在此补全代码 以两种以上方法实现
|
|
|
+ */
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //8、写出下列输出结果
|
|
|
+ // function f() {
|
|
|
+ // return this.a;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // var g = f.bind({ a: "azerty" });
|
|
|
+ // console.log(g());//azerty
|
|
|
+
|
|
|
+ // // 函数正常情况下只能绑定一次bind 但如果绑定了多次 则以第一次绑定为准
|
|
|
+ // var h = g.bind({ a: 'yoo' });
|
|
|
+ // console.log(h());//azerty
|
|
|
+
|
|
|
+ // var o = { a: 'loveCoding', f: f, g: g, h: h };
|
|
|
+ // console.log(o.f(), o.g(), o.h());
|
|
|
+ //loveCoding azerty azerty
|
|
|
+
|
|
|
+
|
|
|
+ //9、补全下列代码
|
|
|
+ // var o = { prop: 'loveCoding' };
|
|
|
+
|
|
|
+ // function independent() {
|
|
|
+ // return this.prop;
|
|
|
+ // }
|
|
|
+ // //在此补全代码
|
|
|
+ // o.f = independent
|
|
|
+ // console.log(o.f()); // loveCoding
|
|
|
+
|
|
|
+ // //10、用call 或 apply 实现bind 方法
|
|
|
+ // function foo() {
|
|
|
+ // console.log(this.a)
|
|
|
+ // }
|
|
|
+ // var obj = {
|
|
|
+ // a: "hello"
|
|
|
+ // }
|
|
|
+
|
|
|
+
|
|
|
+ // var foo2 = foo.bind2(obj);
|
|
|
+ // foo2()
|
|
|
+ </script>
|
|
|
+</body>
|
|
|
+
|
|
|
+</html>
|