Newbie - can.Model.extend


#1

Filter= can.Control.extend({

init: function(){},

getCustomerSearch: function(data){
	console.log(JSON.stringify(data));
},

getCompanyDetails: function(data){
	console.log(JSON.stringify(data));
}

},{})

var FilterSearch= new Filter();
FilterSearch.getCompanyDetails({name: “firstname”});


Encounter this error:

Uncaught TypeError: FilterSearch.getCompanyDetails is not a function

Please advise.


#2

Which version of canjs?


#3

@Sonny_Torres If you pass two arguments to Control.extend, the first argument is for “static” properties… meaning properties you access through the constructor directly like:

Filter.getCompanyDetails( ... );

To do what you want you either want to do:

const Filter = Control.extend(
{}, // pass an empty object for the "static" properties
{
  init: function(){},

  getCustomerSearch: function(data){
    console.log(JSON.stringify(data));
  },

  getCompanyDetails: function(data){
    console.log(JSON.stringify(data));
  }
})

var filterSearch = new Filter(document.createElement("div"));
filterSearch.getCompanyDetails({name: "firstname" });

…or only pass one object to extend, which will be used for “instanceProperties”:

const Filter = Control.extend({
  init: function(){},

  getCustomerSearch: function(data){
    console.log(JSON.stringify(data));
  },

  getCompanyDetails: function(data){
    console.log(JSON.stringify(data));
  }
})

var filterSearch = new Filter(document.createElement("div"));
filterSearch.getCompanyDetails({name: "firstname" });