JS中的簡單繼承 call方法!
阿新 • • 發佈:2018-12-11
function Parent(name, money){ this.name = name; this.money = money; this.info = function(){ alert('姓名: '+this.name+' 錢: '+ this.money); } } //定義孩子類 function Children(name){ Parent.call(this, name); //繼承 姓名屬性,不要錢。 this.info = function(){ alert('姓名: '+this.name); } } //例項化類 var per = new Parent('parent', 800000000000); var chi = new Children('child'); per.info(); chi.info();
bind(), live(), delegate()的區別
bind: 繫結事件,對新新增的事件不起作用,方法用於將一個處理程式附加到每個匹配元素的事件上並返回jQuery物件。
live: 方法將一個事件處理程式附加到與當前選擇器匹配的所有元素(包含現有的或將來新增的)的指定事件上並返回jQuery物件。
delegate: 方法基於一組特定的根元素將處理程式附加到匹配選擇器的所有元素(現有的或將來的)的一個或多個事件上。
看下列程式碼,輸出什麼 var a = new Object(); a.value = 1; b = a; b.value = 2; alert(a.value);//2