<!-- 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);
js中的相关继承
最新推荐文章于 2024-08-08 16:10:15 发布