只有一种情况的,这样就可。
(function() {
function SelectParser() {
this.options_index = 0;
this.parsed = [];
} SelectParser.prototype.add_node = function(child) {
if (child.nodeName === "OPTGROUP") {
return this.add_group(child);
} else {
return this.add_option(child);
}
};
this.SelectParser = SelectParser;}).call(this);对2种以上,这样写法叫(我忘了那专业名词) 一次判定,以后就确定,省了每次都判定。
(function() {
var SelectParser; SelectParser = (function() {
if (11111) {
function SelectParser() {
///11111111
} SelectParser.prototype.add_node = function(child) { };
}
if (22222222) {
function SelectParser() {
///222222
} SelectParser.prototype.add_node = function(child) { };
} return SelectParser; })(); this.SelectParser = SelectParser;}).call(this);
(function() {
function SelectParser() {
this.options_index = 0;
this.parsed = [];
} SelectParser.prototype.add_node = function(child) {
if (child.nodeName === "OPTGROUP") {
return this.add_group(child);
} else {
return this.add_option(child);
}
};
this.SelectParser = SelectParser;}).call(this);对2种以上,这样写法叫(我忘了那专业名词) 一次判定,以后就确定,省了每次都判定。
(function() {
var SelectParser; SelectParser = (function() {
if (11111) {
function SelectParser() {
///11111111
} SelectParser.prototype.add_node = function(child) { };
}
if (22222222) {
function SelectParser() {
///222222
} SelectParser.prototype.add_node = function(child) { };
} return SelectParser; })(); this.SelectParser = SelectParser;}).call(this);
(function(win) {
function SelectParser() {
this.length = 0;
this.list = [];
}
SelectParser.prototype.add_node = function(child) {
this.list.push(child);
this.length++;
};
if(typeof(win.SelectParser) == 'undefined') {
win.SelectParser = SelectParser;
}
})(window);var s = new SelectParser();
s.add_node('aaa');
s.add_node('bbb');
alert(s.list);
alert(s.length);