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
}