I want to familiarize myself with JavaScript and do not know jquery. As a leading JavaScript framework, many of its features are excited. What I have to mention is the unique concatenation writing syntax, so how can he achieve it? Let's also implement one.
SX. $ = function (ID ){
VaR t = (typeof (ID) = "string "? Document. getelementbyid (ID): ID );
T. Text = function (){
Return this. innertext? This. innertext: This. innerhtml. Replace (// <.*? />/IgM ,"");
}
T.html = function (){
Return this. innerhtml? This. innerhtml: NULL;
}
T. First = function (){
Return this. firstchild? This. firstchild. nodename! = "# Text "? SX. $ (this. firstchild): NULL;
}
T. Last = function (){
Return this. lastchild? This. lastchild. nodename! = "# Text "? SX. $ (this. laschild): NULL;
}
T. Pre = function (){
Return this. previussibling? SX. $ (this. previussibling): NULL;
}
T. Next = function (){
Return this. nextsibling? SX. $ (this. nextsibling): NULL;
}
T. Parent = function (){
Return this. parentnode? SX. $ (this. parentnode): NULL;
}
T. setevent = function (e, f ){
If (T. attachevent ){
T. attachevent ("On" + E, F );
} Else {
T. addeventlistener (E, F, false );
}
}
T. removeevent = function (e, f ){
If (T. dettachevent ){
T. dettachevent ("On" + E, F );
} Else {
T. removeeventlistener (E, F, false );
}
}
T. setstyle = function (s ){
VaR S = S. Split (",");
For (VAR I = 0; I <S. length; I ++ ){
VaR S1 = s [I]. Split (":");
This. Style [S1 [0] = S1 [1];
}
}
T. getstyle = function (s ){
If (this. currentstyle ){
Return this. currentstyle [s];
} Else {
Return document. defaultview. getcomputedstyle (this, null). getpropertyvalue (s );
}
}
T. selectpath = function (m ){
VaR M1 = m;
VaR M = M. Split ("/");
VaR T = [];
VaR E = This. getelementsbytagname ("*");
For (VAR I = 0; I <E. length; I ++ ){
VaR e1 = E [I]
VaR A = "";
VaR I1 = M. Length-1;
While (E1! = This ){
A = e1.tagname + "/" +;
E1 = e1.parentnode;
// Alert ();
}
// Alert ();
If (m1.tolowercase () + "/" = A. tolowercase ()){
T. Push (sx. $ (E [I]);
}
}
Return T;
}
T. Get = function (){
Return this. getattribute ();
}
T. Set = function (a, v ){
Return this. setattribute (A, V );
}
T. paste = function (h ){
If (typeof (H) = "string "){
VaR d = Document. createelement ("span ");
D. innerhtml = h;
} Else {
VaR d = Document. createelement ("span ");
D. appendchild (h );
}
VaR T1 = This. childnodes;
For (VAR I = 0; I <t1.length; I ++ ){
Alert (T1 [I])
This. removechild (T1 [I]);
}
This. appendchild (d );
D. removenode (false );
}
Return T;
}
SX. $ = function (){
VaR T = []
For (VAR I = 0; I <arguments. length; I ++ ){
T. Push (sx. $ (arguments [I])
}
Return T;
}
The above code is a core piece of code that I recently wrote in the cross-platform JavaScript framework. It can be seen that I use recursive concatenation syntax and constantly call myself in my own methods, in this way, the experiment closure enables continuous object operations. by the way, I use methods for the t object here. If it is an attribute, it will be displayed in innerhtml.
I'm about to take the test now. I don't have much time to study and study. Although my major has nothing to do with computer science, I wish I don't want to take a class.
I hope you can correct the shortcomings in this article.