I'm learning prototypes, Object.assign but something went wrong

const focus = {
    focus:()=>console.log("focus")  //focus method
function HtmlElement() {
 this.click=()=> console.log("clicked");  //click method 


//  i'm trying to copy focus
// method to HtmlElement

function HtmlSelectElement(){
    let k=[];
    this.addItem=(item)=>k.push(k);  //push the elements
    this.removeItem=(item)=>{        //removes the elements
        for(let i in k){
            if(k[i]===item) {
    Object.defineProperty(this,'k',{   //getter to print the final elements in k
        get : function(){
        return k;
//VEry import NOte: if we do HtmlSelectElement.prototype= Object.HtmlElement.prototype
//it only copies object.htmlelement.prototype methods like focus but 
//it won't copy the click method
//to slove this we have this thing.. as below
HtmlSelectElement.prototype= new HtmlElement();  //copying all members and methods to HtmlSelectElement
let ob1=new HtmlSelectElement(); 

Output: <ref *1> [ [Circular *1], [Circular *1] ]

You have declared focus to be an object with a method named focus. You should not have the semi-colon at the end of the the method definition.

Sir, i changed it but it same error :frowning:

You’re pushing the array k into the array k

1 Like

yes ur right thank u <3

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.