我是javascript对象的新手,在我正在进行的项目中,我设置了一个问题,我必须从内部调用对象构造函数,例如
function MediaRule(name, parent, string) {
this.name = name;
this.parent = parent;
this.rules = new Array();
while(string != "") {
if (string.charAt(0) == '@') {
if (string.search("@keyframes") == 0) {
}
else {
mediaString = new String;
var endString = false;
var nestLevel = 0;
while (endString == false) {
var brace = string.indexOf("}");
var getString = string.substring(0,brace+1).trim();
mediaString += getString;
string = string.replace(getString, "").trim();
if (string.charAt(0) == "@") {
nestLevel++;
}
else if (string.charAt(0) == "}") {
if (nestLevel > 0) {
mediaString += "}";
string = string.replaceAt(0, "");
nestLevel--;
}
if ((nestLevel == 0) && (string.charAt(0) == "}")) {
mediaString += "}";
string = string.replaceAt(0, "");
var aIndex = mediaString.indexOf("{");
var bIndex = mediaString.lastIndexOf("}");
var eleString = mediaString.substring(aIndex+1,bIndex).trim();
var mediaQName = mediaString.substring(0, aIndex).trim();
this.rules.push(new MediaRule(mediaQname, this.name, eleString))
endString = true;
}
}
}
}
}
这个对象构造函数在满足某些条件时从内部一次又一次地被调用,问题是如果我嵌套一个级别但是超出浏览器挂起的情况它会起作用我认为我在调用构造函数的方式上做错了。无论嵌套相同的字符串模式多少次,我希望这个工作。