Briefly describe the efforts of the Mini MVVM frame Avalon in compatibility with legacy IE

Source: Internet
Author: User
Tags class definition join vbscript class

A lot of times, writing code is like building bricks, as long as we do not care about the reasons for building, architectural principles, civil engineering and engineering experience, even if we build 100 high-rise buildings, we are just a brick workers, never become an engineer, let alone architects. And those contractors will only treat us as labor. --The left ear mouse

Avalon has done a lot of work on compatibility with old IE, which makes it more grounded, and runs perfectly in all kinds of exotic flower browsers in China.

The first is the object.defineproperties simulation, which is why the Avalon is a pure event-driven synchronous view without the need for dirty detection, resulting in higher performance.

Ie6-8 using the SET GET statement of the VBScript class
if (!defineproperties && window. VBArray) {
Window.execscript ([
"Function Parsevb (Code)",
"\texecuteglobal (Code)",
"End Function"
].join ("\ n"), "VBScript")

function Vbmediator (accessingproperties, name, value) {
var accessor = Accessingproperties[name]
if (arguments.length = = 3) {
Accessor (value)
} else {
return accessor ()
}
}
defineproperties = function (name, accessingproperties, normalproperties) {
var className = "Vbclass" + settimeout ("1"),
Buffer = []
Buffer.push (
"Class" + className,
"\tprivate [__data__], [__proxy__]",
"\tpublic Default Function [__const__] (d, p)",
"\t\tset [__data__] = D:set [__proxy__] = P",
"\t\tset [__const__] = Me",//Chained call
"\tend Function")
Add normal properties, because VBScript objects cannot be arbitrarily added or deleted as JS, and must be predefined here.
for (name in normalproperties) {
Buffer.push ("\tpublic [" + Name + "]")
}
Buffer.push ("\tpublic [" + ' hasownproperty ' + "]")
Add accessor Properties
for (name in accessingproperties) {
if (!) ( Name in normalproperties)) {//Prevent duplicate definitions
Buffer.push (
Because I do not know what the other party will pass in, so set, let are used
"\tpublic Property Let [" + Name + "] (val" + Expose + ")",//setter
"\t\tcall [__proxy__] ([__data__], \" "+ name +" \ ", Val" + Expose + ")",
"\tend Property",
"\tpublic Property Set [" + Name + "] (val" + Expose + ")",//setter
"\t\tcall [__proxy__] ([__data__], \" "+ name +" \ ", Val" + Expose + ")",
"\tend Property",
"\tpublic Property Get [" + Name + "]",//getter
"\ton Error Resume Next",//must use the SET statement preferentially, otherwise it will mistakenly return the array as a string
"\t\tset[" + name + "] = [__proxy__] ([__data__],\" "+ name +" \ ")",
"\tif err.number <> 0 Then",
"\t\t[" + name + "] = [__proxy__] ([__data__],\" "+ name +" \ ")",
"\tend If",
"\ton Error Goto 0",
"\tend Property")
}
}
Buffer.push ("End Class")//class definition complete
Buffer.push (
"Function" + ClassName + "Factory (A, B)",//create instance and pass in two key parameters
"\tdim o",
"\tset o = (New" + ClassName + ") (A, B)",
"\tset" + className + "Factory = o",
"End Function")
Window.parsevb (Buffer.join ("\ r \ n")//First create a VB class factory
return window[classname + "Factory"] (accessingproperties, vbmediator)//get its product
}

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.