This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //In JS: | |
| let myelem=new MyElement(); | |
| document.body.append(myelem); | |
| //In DOM: | |
| //autonomous Custom Element: | |
| let AutonomousComponent= ()=>(<my-element></my-element>); | |
| //customised button Element: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //defining autonomous custom elements: | |
| if(!customElements.get('my-element')){ | |
| customElements.define('my-element',MyElement); | |
| } | |
| //defining customised button element: | |
| if(!customElements.get('custom-button')){ | |
| customElements.define('custom-button',CustomButton,{extends:'button'}) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let elem=document.createElement('undefinedtag'); | |
| console.log(elem.constructor); //ƒ HTMLUnknownElement() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyElement extends HTMLElement{ | |
| constructor(){ | |
| super(); | |
| console.log('element is instantiated.'); | |
| } | |
| connectedCallback(){ | |
| console.log('element is connected and added to the DOM tree.') | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function* asyncgen(userinput){ | |
| let res= yield userinput; | |
| console.log(res); //print final result; | |
| } | |
| /** doasync() used to fake async task. | |
| * @param: gen {function} generator function as input to be processed. | |
| * @param: val {string} data to be passed. | |
| */ | |
| let doasync=(gen,val)=>{ | |
| var getdata=gen(val); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let fakearray={ | |
| *[Symbol.iterator](){ | |
| let i=0; | |
| while(i<10){ | |
| i++; | |
| yield i; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let fakearray={ | |
| [Symbol.iterator](){ | |
| let x=0,done=false; | |
| return { | |
| next(){ | |
| x++; | |
| if(x>10)done=true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let childgen=function*(){ | |
| yield 'child 1'; | |
| yield 'child 2'; | |
| return 'child 3'; | |
| } | |
| let parentgen=function*(){ | |
| yield 'parent 1'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let yielder=function*(){ | |
| yield yield yield 'first'; | |
| } | |
| let race=yielder(); | |
| console.log(race.next()); //@yields {value: "first", done: false} | |
| console.log(race.next('second')); //@yields {value: "second", done: false} | |
| console.log(race.next('third')); //@yields {value: "third", done: false} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let race=genRace(); // Generator object created. | |
| console.log(race.next()); // @yields {value: "first", done: false} | |
| console.log(race.next()); // @yields {value: "second", done: false} | |
| console.log(race.next()); // @yields {value: "third", done: false} | |
| console.log(race.next()); // @returns {value: "stupid race", done: true} | |
| console.log(race.next()); // @returns {value: undefined, done: true} |