@@ -80,35 +80,31 @@ ezjQuery
8080 */
8181
8282let ezjQuery = {
83- collector : [ ] ,
8483 arrayWithOpenTags : [ ] ,
8584 arrayWithClosenTags : [ ] ,
8685 arrayWithStuctureWithValue : [ ] ,
8786 add ( tagName , value ) {
88- if ( [ ... arguments ] . length === 1 ) {
87+ if ( tagName && ! value ) {
8988 const openTag = `<${ tagName } >` ;
9089 const closenTag = `</${ tagName } >` ;
9190 this . arrayWithOpenTags . push ( openTag ) ;
9291 this . arrayWithClosenTags . unshift ( closenTag ) ;
9392 }
94- if ( [ ... arguments ] . length === 2 ) {
93+ if ( tagName && value ) {
9594 const stuctureWithValue = `<${ tagName } >${ value } </${ tagName } >` ;
9695 this . arrayWithStuctureWithValue . push ( stuctureWithValue ) ;
9796 }
9897
9998 return this ;
10099 } ,
101100 render ( ) {
102- const copyCollector = this . collector ;
103- const firstIterationOfConcat = copyCollector . concat ( this . arrayWithOpenTags ) ;
104- const secondIterationOfConcat = firstIterationOfConcat . concat ( this . arrayWithStuctureWithValue ) ;
105- const thirdIterationOfConcat = secondIterationOfConcat . concat ( this . arrayWithClosenTags ) ;
101+ const finalArray = [ ...this . arrayWithOpenTags , ...this . arrayWithStuctureWithValue , ...this . arrayWithClosenTags ] ;
106102
107103 this . arrayWithOpenTags = [ ] ;
108104 this . arrayWithClosenTags = [ ] ;
109105 this . arrayWithStuctureWithValue = [ ] ;
110106
111- return thirdIterationOfConcat . join ( '' ) ;
107+ return finalArray . join ( '' ) ;
112108 }
113109} ;
114110
@@ -140,3 +136,37 @@ console.log(bodyDiv); //<body><div></div></body>
140136 * $('body').add('li', 'hi').render() // <body><li>hi</li></body>
141137 *
142138 * */
139+ function dolar ( tagName ) {
140+ let obj = { } ;
141+ obj . arrayWithOpenTags = [ ] ;
142+ obj . arrayWithClosenTags = [ ] ;
143+ obj . arrayWithStuctureWithValue = [ ] ;
144+
145+ obj . add = function ( tagName , value ) {
146+ if ( tagName && ! value ) {
147+ const openTag = `<${ tagName } >` ;
148+ const closenTag = `</${ tagName } >` ;
149+ this . arrayWithOpenTags . push ( openTag ) ;
150+ this . arrayWithClosenTags . unshift ( closenTag ) ;
151+ }
152+ if ( tagName && value ) {
153+ const stuctureWithValue = `<${ tagName } >${ value } </${ tagName } >` ;
154+ this . arrayWithStuctureWithValue . push ( stuctureWithValue ) ;
155+ }
156+
157+ return this ;
158+ } ;
159+ obj . render = function ( ) {
160+ const finalArray = [ ...this . arrayWithOpenTags , ...this . arrayWithStuctureWithValue , ...this . arrayWithClosenTags ] ;
161+
162+ this . arrayWithOpenTags = [ ] ;
163+ this . arrayWithClosenTags = [ ] ;
164+ this . arrayWithStuctureWithValue = [ ] ;
165+
166+ return finalArray . join ( '' ) ;
167+ }
168+
169+ if ( tagName ) {
170+ return obj . add ( tagName ) ;
171+ } else return obj ;
172+ }
0 commit comments