js中的相关继承


	<!-- DOM:可以间接操作css -->
	元素节点:1
	属性节点:2
	文本节点:3
	注释节点:8
	<div>
		<span></span>
	</div>
	<script>
		构造函数首字母必须大写  -> 比如Document是document的原型
		Document.prototype.abc = 'abc';
		document.abc
		document -> 对应构造函数HTMLDocument
		Document.prototype. -> HTMLDocument.prototype -> document.prototype(原型是上一级)

		HTMLDocument.prototype = {
			__proto__:Document.prototype
		}

		document -> 继承HTMLDocument.prototype -> 原型链继承
		{xmldocument,htmldocument}

        HTMLBodyElement.prototype.abc = 'demo';
        var body = document.getElementsByTagName('body')[0];//拿到页面
        body.abc = 'demo';//此时body的原型改变
        // HTMLBodyElement <body>元素公开HTMLBodyElement接口。您可以通过document.body属性访问body元素。
        document.__proto__ -> HTMLDocument 原型
        document.__proto__.__proto__ -> Document 原型的原型 
        document.__proto__.__proto__.__proto__ ->Node
        // 最终继承Object

        var div = document.getElementsByTagName('div')[0];
        var span = div.getElementsByTagName('span')[0];
        //锁定区域选定元素,使得选取更加快速

        document.body//即选出body便签及其内容
		// // <body>​…​</body>​
		// document.head //同理
		// document.documentElement;//选出html标签


		// function print(){
		// 	console.log(fool);
		// 	var fool = 2;
		// 	console.log(fool);
		// 	console.log(hello);
		// }
		// print();

		// function print(){
		// 	var test;
		// 	test();    -> 1
		// 	function test(){
		// 		console.log('1');
		// 	}
		// }
		// print();
		//如果按照优先级的话,var声明的变量应该确实比函数声明更加高级,但是function之后会覆盖之前的变量声明,尽管var有变量声明提升机制

		var bar = {
			a:"002"
		}
		function print(){
			bar.a = 'a';
			Object.prototype.b = b;
			return function inner(){
				console.log(bar.a);//a
				console.log(bar.b);//b
			}
		}
		print()();
		//对于这个函数,bar.a = 'a';未声明所以归全局所有 那么{a:002 -> a:a}
		//对于bar.b 这里应该是要从原型链上去找
		//print()();先返回(return)函数(此时bar.a已经变成了{a:a}) 后函数执行
			// return function inner(){
			// 	console.log(bar.a);//a
			// 	console.log(bar.b);//b往原型链上找
			// }

		var obj = {
			name:'a',
			age:11,
			sex:'female'
		}
		var obj1 = {};
		function clone(origin,target){
			var target = target || {};//防止用户不传
			for(var prop in origin){
				target[prop] = origin[prop]
			}
			return target;
		}
		clone(obj,obj1);

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值