OOP scope JavaScript

Gives an error message,
Uncaught SyntaxError: missing ) after argument list (at script.js:15:64)

 class  Block {
  constructor(type, value, options){
this.type = type
this.value = value
this.options = options
  }
}

const tect = 'Круты видео и уроки по JavaScript тут:Максим Реутов.Тут ты найдешь исчерпывающую информацию по любым аспектам языка,любым фреймворкам,такие как:React,Vue,Angular,Node,Svelte,Express,Next,Nuxt и многое другое.Присоединяйтесь!'



const model = [
  
  new Block('title','Конструктор сайтов на чистом JavaScript', options: {
    tag: 'h2',
    styles: {
      background:'linear-gradient(to right, #ff0099, #493240)',
      color: '#fff',
      padding: '1.5rem',
      'text-align': 'center'
    }
  }),
  { type: "colomns", value: [
    "Приложение на чистом JavaScript, без использования библиотек",
     "Узнаешь как работает принцип SOLID and ООП в JavaScript за один курс", 
     "JavaScript - это просто, интересно. Научись создавать любые UI своими руками", 
    ],options: {
styles: {
  background: 'linear-gradient(to bottom, #8e2de2, #4a00e0)',
  padding: '2rem',
  color: '#fff',
  'font-weight': 'bold'
}
    }
  
  },
  new Block('image', './img/images.jpeg', options: {
    styles: {
      padding: '2rem 0',
      display: 'flex',
      'justify-content': 'center',
     
    },
      imageStyles: {
        width: '400px'
        
      },
       alt: 'Это картинка'
  }),
     
    
     
    
  { type: "text", value: tect, options: {
    styles: {
      background:'linear-gradient(to left, #f2994a, #f2c94c)',
      padding: '2rem',
      'font-weight': 'bold'
    }
  } },
];

You should remove the last comma

Which one of?

Thallius means what he said. The last comma. Start at the end of your code, and walk backwards until you find a comma; delete it.

However, that’s not the problem here. (Well, okay, not the one that’s causing the error message, anyway)

Specifically, the script is throwing an error here:

new Block('title','Конструктор сайтов на чистом JavaScript', options: {
Why?

Javascript doesnt use named parameter calling. Why is the word “options:” here? You’re not in the middle of an object at that point. Remove the word “options” and the colon, and just start an object (which is what the constructor function is expecting).

Hint: You do this twice.

I have styles in the options, even if I remove the options, a bunch of other errors appear

I didnt say remove the object. I said remove the word options and the colon from that line.

This solution worked, but how it works is not clear.

To be honest , it looks like you are totally overburdened by the project you are doing. Maybe you should start with a real starters tutorial which gives you the basics of programming.

I have to agree with Thallius… the tutorial you’re following doesn’t seem to be angled towards true beginners, more of a concept-introduction to those who already have the basics.

What you are doing on line 15 is creating a new object of type Block.
new Block(

The object needs parameters for its constructor, which you defined above:

 class  Block {
  constructor(type, value, options){
    this.type = type
    this.value = value
    this.options = options
  }
}

the constructor for Block takes 3 parameters, type, value, and options.

When you call it, it knows what its expecting: 3 parameters. The first thing you give it will be type, the second value, and the third options. It’s not written down, but from the examples, we can deduce that type and value should be strings, and options should be an object.

Lets say we had no options. Just to clean up some of the clutter.

I could create a Block, by sending my stuff to it:
new Block("MyType","My Value",{})
I don’t have to tell the constructor which parameter is which, it knows based on the position. Note that even though I have no options, I have to send something as the third parameter - so I send an empty object. That way the code doesn’t get fussy later on if it tries to use it as an object.

Feeling a bit guilty for my comment in pinkod02’s other thread.

Personally I’d say go for it :slight_smile:

Possibly bad advice on my part, I think you could be right. Maybe come back to this one.

Every day I read something or watch similar topics, but it’s all very difficult to understand, and much is simply not clear, even if you say it 10 times, because in order to understand you need to understand the chain, and it’s not always easy to finish.

And I see every day postings of people who want to learn programming by watching videos which show how to create complex applications.

When I started programming (over 40 years ago) we started with „hello world“, then we did something like calculating Fibonacci or similar. The whole code was written by myself, character for character without any example.
You do not learn by copying code from the net and try to make a program out of it. You learn by create your own code step by step and yes, learning to be a good programmer takes month, if not even years…

yes, I already understood that it takes years to study, but on the other hand, it’s very sad, I look at the statistics of graduates, in the CIS countries only one out of about 800 people finds a job))

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