Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!