问题描述
<SCRIPT LANGUAGE="JavaScript">var name = "woziji";function showObj(val,params){var hanshu='dd';function _new(){alert(this.name);this.ff.call(this,params);}_new.prototype = val;return new _new();}var val = {test:'gwj',ff:function(test){this.test=test;},show:function(){alert(this.test+" -- ");}};var ss = new showObj(val,'qqqqqqq');ss.show();</SCRIPT>
解决方案
this代表当前 _new 并设置了_new属性为val,_new.prototype = val; 所以你this能访问val对象,通过 函数 call apply 都能改变 this 对象
时间: 2025-01-07 07:15:09