看js运行结果

1. 

function A(name){
	if(name){ // false
		// 这行没有进来
		this.name="Kate"
	}
}

function B(name){
	console.log(name); // undefined
	this.name = name;
}

function C(name){
	this.name = name || "Jack";
}

A.prototype.name="tom";
B.prototype.name="tom";
C.prototype.name="tom";

//tom undefined Jack
console.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); // window
				console.log(number); // undefined
				
				number = 4;
				console.log(window.number); //2
				console.log("a " + number); // 4

				var number;
				console.log("b " + number); // 4

				number = number * 2;
				console.log("c " + number); //8

				getNumber();

				function getNumber() {
					console.log("d " + this.number); // 2
					return this.number;
				}
			}
			
			getNumber2();
			console.log(number); //2

			//console.log("e " + getNumber2()); // undefined
			console.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); // tom

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

a.name="aaa";
console.log(b.name); // tom

6.

name = "win";

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

getName(); // 1 win
a();// 2 a   3 a
getName(); // 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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值