看js运行结果

来源:互联网 发布:数据库基础视频 编辑:程序博客网 时间:2024/04/20 01:18

1. 

function A(name){if(name){ // false// 这行没有进来this.name="Kate"}}function B(name){console.log(name); // undefinedthis.name = name;}function C(name){this.name = name || "Jack";}A.prototype.name="tom";B.prototype.name="tom";C.prototype.name="tom";//tom undefined Jackconsole.log(new A().name + new B().name + new C().name);


2.


3. 

<!DOCTYPE HTML>  <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><script type="text/javascript">var number = 2;function getNumber() {return this.number;}function getNumber2() {console.log(this); // windowconsole.log(number); // undefinednumber = 4;console.log(window.number); //2console.log("a " + number); // 4var number;console.log("b " + number); // 4number = number * 2;console.log("c " + number); //8getNumber();function getNumber() {console.log("d " + this.number); // 2return this.number;}}getNumber2();console.log(number); //2//console.log("e " + getNumber2()); // undefinedconsole.log("f " + getNumber()); // 2</script></body></html>




4.  css继承优先级由上到下

<!DOCTYPE HTML><html><head><title>123</title><style type="text/css">#divid a{color: red;}.divclass a{color: yellow;}span a{color: green;}a{color: blue;}</style></head><body><div id="divid"><div class="divclass"><span><a href="http://www.baidu.com/">red</a></span></div></div></body></html>

5. 

var a = {name:"haojie", age:"1"};b=a;a.name="tom";console.log(b.name); // toma = {name:"zzy", age:1};console.log(b.name); // toma.name="aaa";console.log(b.name); // tom

6.

name = "win";function getName(){console.log("11 " + this); // windowconsole.log("1 " + this.name);}function a(){console.log("22 " + this); // windowthis.name="a";console.log("2 " + this.name);getName();function getName(){console.log("33 " + this); // windowconsole.log("3 " + this.name);return this.name;}}getName(); // 1 wina();// 2 a   3 agetName(); // 1 a


<!DOCTYPE HTML>  <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><script type="text/javascript">var myObject1 = {};myObject1 = function(){console.log(this); // Window}myObject1();var myObject2 = {};myObject2.haha = function(){console.log(this); // Object{haha:function}}myObject2.haha();// 不好理解?换种写法var myObject3 = {haha:function(){console.log(this); // Object{haha:function}}};myObject3.haha();</script></body></html>

<!DOCTYPE HTML>  <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><script type="text/javascript">function add(a){console.log(this);console.log(a);}var myObject = {};myObject.haha = function(){console.log(this);var that = this;var helper = function(){add(this);//add(that);}helper();}myObject.haha();</script></body></html>

原创粉丝点击