读书人

请问一个字符串转函数方法

发布时间: 2013-08-04 18:26:16 作者: rapoo

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


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');

读书人网 >JavaScript

热点推荐