作者:mobiledu2502894753 | 来源:互联网 | 2023-10-10 15:59
1.压缩前的js
1 2 3 4 5 6 7 8 9 10 11 12 13
| (function () {
var Test = function (name, age) {
this.name=name;
this.age=age;
}
Test.prototype={
getName:function () {
return this.name + ' haha';
}
}
var testA = new Test('xiao',12) // 这里获取得到 Test对象
console.log(testA.getName());
})() |
2.压缩后的js
1
| !function(){var e=function(e,n){this.name=e,this.age=n};e.prototype={getName:function(){return this.name+" haha"}};var n=new e("xiao",12);console.log(n.getName())}(); |
3.在html中引入压缩后的js后,
1 2
| var testA = new Test('xiao', 12) // 这里找不到 Test对象
console.log(testA.getName()); |
请问一下,js代码压缩前要怎么改写才能解决这个问题?