encode脚本和normal脚本混用的问题与解决方法

2019-06-03 03:02:42王冬梅

        };  
    </script> 
    <script language="jscript" type="text/jscript"> 
        var msg = '.prototype.Message" Fail.<br>'; 
        function WriteLine(msg) { document.write(msg + '<br><br>'); } 

        var o = new Object(); 
        try { o.Message(); } 
        catch(e) { WriteLine('Call "Object' + msg + e.message); } 
        try { Object.Message(); } 
        catch(e) { WriteLine('Call "Object.Message" Fail. <br>' + e.message); } 

        var e = new Encode(); 
        try { e.Message(); } 
        catch(e) { WriteLine('Call "Encode' + msg + e.message); } 
        Encode.Message(); 

        var n = new Normal(); 
        try { n.Message(); } 
        catch(e) { WriteLine('Call "Normal' + msg + e.message); } 
        Normal.Message(); 
    </script> 
</body> 
</html> 

    把上面的代码存为一个*.htm文件,打开后得到结果为: 

  Call "Object.prototype.Message" Fail.
  Object doesn't support this property or method
  Call "Object.Message" Fail. 
  Object doesn't support this property or method
  Encode.prototype.Message
  Encode.Message
  Normal.prototype.Message
  Normal.Message
    上面那两段jscript.encode的代码很简单,就是: Object.prototype.Message = function()
{
    alert('Object.prototype.Message');
};
Object.Message = function()
{
    alert('Object.Message');
}; 
function Encode() {}
Encode.prototype.Message = function()