Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

203
Visualizações
'constructor' is not defined

I am trying to make a programming language (very stupid), and i stumble across this error:

ReferenceError: ' constructor' is not defined.

Here is where the code is (Node JS):

class DLang {
  constructor(code) {
    this.lines = code.split('\n')
  }

  run() {
    let lines = this.lines
    let testingUtils_ = false
    let variables = {}

    for (let i = 0; i < lines.length; i++) {
      if (lines[i] === 'import \'testing/all.dlang\'') {
        testingUtils_ = true
      }

      if (lines[i].includes('(')) {
        let currFunction_ = lines[i].split('(')[0]
        // let text = lines[i].split('(')[1].replace(')', '').replace(/\'/g, '')
        let text
        let value = lines[i]
                    .replace('(', '')
                    .replace(')', '')
                    .replace(currFunction_, '')

        if (value.includes('\'')) {
          text = value
                  .replace(/\'/g, '')
        } else {
          text = variables[value]
        }
  
        // function conditions
        let printCondition_ = (currFunction_ === 'print' && testingUtils_ === true)
  
        if (printCondition_) {
          if (text == undefined) {
            throw ReferenceError(`\'${value}\' is not defined.`)
          } else {
            console.log(text)
          }
        } else if (!printCondition_) {
          throw new ReferenceError(`\'${currFunction_}\' is not defined.`)
        }
      }

      if (lines[i].includes('var', 0)) {
        let final_ = lines[i]
                      .replace('var', '')
                      .replace('=', '')
                      .trim()
                      .split('\'')

        variables[final_[0].trim()] = final_[1]
      }
    }
  }
}

module.exports = DLang

For reference, here is the full error message:

throw new ReferenceError(`\'${currFunction_}\' is not defined.`)
          ^

ReferenceError: '  constructor' is not defined.
    at DLang.run (/Users/name/Desktop/coding/programming_langs/dlang/dlang_source_code/src/index.js:42:17)
    at /Users/name/Desktop/coding/programming_langs/dlang/dlang_source_code/test.js:11:7
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)

Node.js v17.1.0

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda