frond end 总结

problems with prototypes.

  1. all instance get the same property values by default.
  2. the main problem comes with their shared nature for example : person1.friends array push a new stuff.   person2.frend also change.

 

 

constructor vs instance vs prototype 

each constructor has a prototype object that points back to the constructor and instances have an internal pointer to the prototype.

 

 

inheritance using prototype chaining.

function SuperType(){

this.property = true;

}

SuperType.prototype.getSuperValue = function(){

return this.property;

};

function SubType(){

this.subproperty = false;

}

//inherit from SuperType

SubType.prototype = new SuperType();

SubType.prototype.getSubValue = function (){

return this.subproperty;

};

var instance = new SubType();

alert(instance.getSuperValue()); //true

 

The HTML DOM (Document Object Model)

  • Finding HTML elements by id          var x = document.getElementById("main").
  • Finding HTML elements by tag name    var y = x.getElementsByTagName("p").  y[0].innerHTML
  • Finding HTML elements by class name   Finding elements by class name does not work in Internet Explorer 5,6,7, and 8.

 

 

event Bubbling and capturing

http://javascript.info/tutorial/bubbling-and-capturing

Bubbling,   d3->d2->d1

After an event triggers on the deepest possible element, it then triggers on parents in nesting order.

<!DOCTYPE HTML>
<html>
<body>
<link type="text/css" rel="stylesheet" href="example.css">

<div class="d1">1  <!-- the topmost -->
    <div class="d2">2
        <div class="d3">3 <!-- the innermost -->
        </div> 
    </div>
</div>

</body>
</html>

Capturing

1->2->3  need to use the addEventListener method.

All methods of event handling ignore the caputiring phase. Using addEventListener with last argumenttrue is only the way to catch the event at capturing

elem.addEventListener( type, handler, phase )

 

phase = true
The handler is set on the capturing phase.
phase = false
The handler is set on the bubbling phase.
1->2->3
var divs = document.getElementsByTagName('div')

for(var i=0; i<divs.length; i++) {
  divs[i].addEventListener("click", highlightThis, true)
}

   1->2->3->3->2->1

var divs = document.getElementsByTagName('div')

for(var i=0; i<divs.length; i++) {
  divs[i].addEventListener("click", highlightThis, true)
  divs[i].addEventListener("click", highlightThis, false)
}

 

 

 

 

 

转载于:https://www.cnblogs.com/leetcode/p/3165349.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值