Encode scripts and normal scripts mix problems and solutions _javascript tips

Source: Internet
Author: User
Tags mixed wrapper
Six months ago the first time to do script coding, because there is no use experience, so on the 51JS asked the encode script and normal script mixed with what is the problem? The results did not get any constructive comments, which also explained at least two questions, one is no one cares, and second, there is no problem. Of course I was more than happy to accept the latter result, and I started a mixed use of the encode script and the normal script.

In this understanding to do a lot of the script, it seems that there is really no problem, so more firmly believe in their original judgment. The result is once again by IE plot, encode script and normal script mix and use is not no problem, also not all have problems, just under certain conditions will be a problem, really faint death. Look at the following example:

Copy Code code as follows:

<title>jscript Encode research</title>
<meta name= "Author" content= "Birdshome@cnblogs"/>
<body>
<script language= "Jscript.encode" type= "Text/jscript.encode" >
#@~^8gaaaa==~,p~,p,pr (l^ycw.wdwoza+rtn/klo~xp6e mokguv#@#@&,~p,p~~, @#@&~,p~p,~,p~,p,lvddcb}4%+1y 2MWYKOXA+RTND/MOBBI@#@&AMP;,P~P,~P,8I@#@&AMP;PP~~,P~P@#@&AMP;,P~,P,PP}4NNMDR\+K/CLP ', WE MYbGU ' *@#@&P~P~~, p~ @#@&p,p~~,pp~~,p~l^nmycer (l+1yc\+k/cobbi@#@&p,~p,pp,nigjkaaa==^#~@
</script>
<script language= "Jscript.encode" type= "Text/jscript.encode" >
#@~^fgeaaa==~,p~,p,p0!x1okkx~2mg[' #, ' 8@#@&@#@&~~p,p,p~2u^knnra.wdwoza+r\nk/co~{pw!x1ykkxvb@#@&p~  p,p~~, @#@&~p,pp,~~p,p,.kondku+vv2 mg[rw.gdwoxanchnk/mo+e#p@#@&,p~p,p~~) i@#@&@#@&,PP,~~P,2 mGNn t+d/ml+, ' ~w!xmorkxc#@#@&,p~,p,ppp@#@&~p,p~p,p~~,pmrysk ncbax1w[+ \/dltnb*i@#@&,pp~~,p~8p~,v0maaa= =^#~@
</script>
<script language= "JScript" type= "Text/jscript" >
function Normal () {}
Normal.prototype.Message = function ()
{
WriteLine (' Normal.prototype.Message ');
};
Normal.message = function ()
{
WriteLine (' normal.message ');
};
</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>

Save the above code as a *.htm file, and open it and get the result:

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
The above two paragraphs Jscript.encode's code is very simple, is: Object.prototype.Message = function ()
{
Alert (' Object.prototype.Message ');
};
Object.message = function ()
{
Alert (' Object.message ');
};
function Encode () {}
Encode.prototype.Message = function ()
{
WriteLine (' Encode.prototype.Message ');
};
Encode.message = function ()
{
WriteLine (' encode.message ');
};
If we replace the previous two pieces of code with the two-segment Jscript.encode code in that HTML, the next run will be no exception, and the output will be: Object.prototype.Message
Object.message
...
The test of these code examples above has already explained the problem of encode script code in detail. Is that you cannot refer to the prototype (prototype) method and static methods that are imported into the JScript built-in objects in the encoding script in an encoding script. The object in the example above is a built-in object of JScript, and we import a Prototpye method and a static method message () separately. For non-built-in object encode, the prototype and static methods that we import in encoded code can be accessed normally in code that is not encoded.

So how do you access the built-in object's import method? In fact, the solution is not complicated, but more cumbersome. We need to use some wrapper methods to put them together with the coded code, which can be accessed in the encoding code, such as the import of the object above, which we can wrap:

Object.prototype.Message = function ()
{
WriteLine (' Object.prototype.Message ');
};
Object.message = function ()
{
WriteLine (' object.message ');
};
var obj = new Object ();

function Objectprototypemessage ()
{
Obj. Message ();
}
function ObjectMessage ()
{
Object.message ();
}
At this point, we can access the imported methods of the built-in objects in encoded code through wrapper methods such as Objectprototypemessage and ObjectMessage.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.