Created
May 27, 2012 15:04
-
-
Save greyd/2814614 to your computer and use it in GitHub Desktop.
ДЗ 5 таск 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var paragraph = (function() { | |
var attrWhiteList = /^(text|size|color|weight|true)$/i; | |
var paragraph = {}; | |
function setAttr(name, value) { | |
if(typeof name == 'string') { | |
if(checkAttr(name)) { | |
paragraph[name] = value; | |
} | |
} else { | |
for(var key in name) { | |
if(checkAttr(key)) { | |
paragraph[key] = name[key]; | |
} | |
} | |
} | |
} | |
function checkAttr(name) { | |
return attrWhiteList.test(name); | |
} | |
return { | |
getParagraph : function() { | |
console.log(paragraph); | |
return paragraph; | |
}, | |
setAttr : setAttr | |
}; | |
})(); | |
paragraph.setAttr('text', 'textetxtetxt'); | |
paragraph.setAttr({ | |
color : 'red', | |
size : 100 | |
}) | |
paragraph.setAttr(function(){}) | |
paragraph.setAttr([1,2,3]) | |
paragraph.getParagraph(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment