For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Saturday, May 25, 2024

Simple Class in JavaScript

Simple Class in JavaScript


Here is the below code that demonstrate that how to create class and how to use it.


<script>
class WORKER {
    #step1(){console.log("RUN step1");}
    #step2(){console.log("RUN step2");}
    #step3(){console.log("RUN step3");}
    #step4(){console.log("RUN step4");}
    #step5(){console.log("RUN step5");}
    init() {
        this.#renderHTMLFromURL();
    }
    #renderHTMLFromURL = () => {
        this.#step1();
    this.#step2();
    this.#step3();
    this.#step4();
    this.#step5();
    }
}
new WORKER().init();
</script>

Share:

Tuesday, May 21, 2024

Run multiple tasks one by one in javascript

 Run multiple tasks one by one in javascript

 

 Here is the code in JavaScript code that demonstrate how to run multiple tasks one by one.

<script>
const one=()=>{console.log(“I am function One”);}
const two=()=>{console.log(“I am function Two”);}
const three=()=>{console.log(“I am function Three”);}
const four=()=>{console.log(“I am function Four”);}
const yieldToMainThreadWork =()=> {
return new Promise(resolve => {
setTimeout(resolve, 2500);
});
}
//async function runAll () {
const runAll = async ()=>{
const tasks=[one,two,three,four];
while (tasks.length > 0) {
const task = tasks.shift();
task();
await yieldToMainThreadWork();

}
}
runAll();
</script>

 

Share:

How to make center align child div

 How to make center align child div?   Suppose you have 2 Div tag. And want the make inner tag center <div id="d1">      ...

Ads Inside Post

Powered by Blogger.

Arsip