# Lesson-1
===
這個版本呢,先來加四個很簡單的方法感受感受下!
首先3個class不用說了
```javascript
hasClass : function(cls) {
var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
for (var i = 0; i < this.length; i++) {
if (this[i].className.match(reg)) return true;
return false;
}
return this;
},
addClass : function(cls) {
var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
for (var i = 0; i < this.length; i++) {
if(!this[i].className.match(reg))
this[i].className += ' ' + cls;
}
return this;
},
removeClass : function(cls) {
var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
for (var i = 0; i < this.length; i++) {
if (this[i].className.match(reg))
this[i].className = this[i].className.replace(cls,'');
}
return this;
}
```
然后新增一個
```javascript
css : function(attr,val) {//鏈式測試
console.log(this.length);
for(var i = 0;i < this.length; i++) {
if(arguments.length == 1) {
return getComputedStyle(this[i],null)[attr];
}
this[i].style[attr] = val;
}
return this;
}
```
這些其實都很簡單,我們都要記住,我們封裝的DOM對象是一個數組,所以一定都需要用循環來進行各種個樣的處理.
然后css這我是用arguments的個數來進行判斷是取值還是社值.
最后千萬別忘了每個方法的最后都要return this以便鏈式調用.
大家可以自行拿這幾個方法 log出來看看是否是與jQuery的一樣就知道是否成功了.