Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="passing arguments to parent in es6">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
    class Parent {
      constructor(args = {}){
                //destructure what you need here
                let {
                    a = "default a", 
                    b = "default b", 
                    c = "default c"
                } = args
        this.a = a
        this.b = b
        this.c = c
      }
    }
    class Child extends Parent {
      constructor(args = {}){
                //pass args object
                super(args)
                //destructure what you need here
                let {
                    d = "default d",
                    e = "default e"
                } = args
        this.d = d
        this.e = e
      }
    }
        let parent = new Parent({
            a: "Param A", 
            b: "Param B", 
            c: "Param C"
        })
        
        let child = new Child({
            a: "Param A", 
            e: "Param E",
            c: "Param C"
        })
        
        console.log(parent)
        
        console.log(child)
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
keithriverpro
0viewers