是否有执行的性能开销sb.indexOf(c + "")
,其中c是类型Character还是char和sb为StringBuilder对象?
我想知道是否有更好的方法来实现createEmployee(),它使用字典或其他方式快速查找所请求的类型而不是if-else块.
function Clerk( options ) {
this.hourRate = options.hourRate || 20;
this.firstName = options.firstName || "no first name";
this.lastName = options.lastName || "no last name";
this.id = options.id || "-9999999999";
}
function Manager( options) {
this.hourRate = options.hourRate || 200;
this.firstName = options.firstName || "no first name";
this.lastName = options.lastName || "no last name";
this.id = options.id || "-9999999999";
this.yearBonus = options.yearBonus || "200000";
}
function Teacher( options) {
this.hourRate = options.hourRate || 100;
this.firstName = options.firstName || "no first …Run Code Online (Sandbox Code Playgroud)