Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

121
Vistas
object is possibly undefined error when trying to declare a variable in backbone model

I am using a backbone model:

export class test = Backbone.Model.extend({
     defaults: {
     name : ''},
     x = 'test'
)}{

function(){
console.log(this.x)}
}

However I get an error on the console. log that says 'property x may not exist on type test'. Am I declaring global variables wrong in backbone? Im quite new to js

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

To access x defined in the Backbone Model/View and access it from somewhere else, you can define it as an attribute like so: x: null or give any value. By the way, defining it is not mandatory.

var TestModel = Backbone.Model.extend({
    defaults: {
        name: '',
        x: 0,
    },
});

var myTestModel = new TestModel();

console.log(myTestModel.x);

This would print zero.

You can do the same with a view.

Does this answer your question?

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda