日期:2014-05-16  浏览次数:20372 次

请教一个字符串转函数方法。

function cls(){
this.A = function(s){
var x = s + 'MX';
//问题在这里
this.x();
//我想得出i am here的结果,这里的"x"这个字符串应该如何进行转化?
}

this.techMx = function(){
alert('i am here');
}
}

var j = new cls();
j.A('tech');

------解决方案--------------------
    function cls() {
        this.A = function (s) {
            var x = s + 'Mx';//注意大小写
            this[x]();///////////
        }

        this.techMx = function () {
            alert('i am here');
        }
    }

    var j = new cls();
    j.A('tech');