Category : es6-class

I want to run the code below successfully. import newsapi from "newsapi"; const NewsAPI = new newsapi(‘***************************’); class newsApiHeadlines { constructor () { this.init(); } async init () { this.newsApiRes = await NewsAPI.v2.topHeadlines({ country: ‘us’, }); } getTopHeadlineTitle () { return this.newsApiRes.articles[0].title; } } let objNewsApi = new newsApiHeadlines(); console.log(`Title:n${objNewsApi.getTopHeadlineTitle()}`); Of course, the code resulted ..

Read more

for the function declaration without arrow function person.printNameFunction() on calling it is printing undefined. Why so and how can we make it work and print what’s intended. class Person { constructor(name) { this.name = name; } printNameArrow() { setTimeout(() => { console.log("Arrow: " + this.name); }, 100); } printNameFunction() { setTimeout(function () { console.log("Function: " ..

Read more

I’m trying to encapsulate common functionality in base class and planning to invoke derived class specific function from their respective instances. Somehow, I’m not getting parameters in derived class. not sure what’s wrong here – class A { constructor(callback){ this.callback = callback; } write(){ console.log(‘Writing A’); this.callback(10); } } class B extends A { constructor(){ ..

Read more

//module1 const B=require("./module2") module.exports=class A{ constructor(){} static fun(){ B.func()….. } } module2 const A=require("./module1") module.exports=class B{ constructor(){} static fun(){ A.fun()… } } When i console typeof class ‘B’ from A instead of showing functio it showing type as an object ie:-the class becoming an empty object {} how to access class methods correctly. It showing ..

Read more

I have a script where I append an external JS script, Amazon IVS video player, to the page. I then create a new CustomPlayer instance from my CustomPlayer class. main.js import CustomPlayer from ‘./CustomPlayer.js" var s = document.createElement("script"); s.type = "text/javascript"; s.src = "https://player.live-video.net/1.3.1/amazon-ivs-videojs-tech.min.js"; $("body").append(s); const customConfig = { autoPlay: true, controls: true }; const ..

Read more