function A() { this.do1 = function () { console.log(1); }; this.do2 = function () { console.log(2); }; } var a = new A(); var keys = Object.keys(a); for(var i=0;i<keys.length;i++){ if(typeof a[keys[i]] ==="function"){ a[keys[i].toUpperCase()] = a[keys[i]]; delete a[keys[i]]; } } a["DO1"](); //1
时间: 2024-10-07 15:38:31