Reputation: 7631
I am beginner in towards backbone.js. Here is what i am working towards.
Person = Backbone.Model.extend({
defaults: {
name: 'Fetus',
age: 0,
children: []
},
initialize: function(){
//alert("Welcome to this world");
}
});
var person = new Person({name: 'John', age: '100'});
delete person;
//var person = new Person;
//person.set({name: 'Cooper', age: '90'});
alert(person.get('name') + ' ' + person.get('age'));
Upvotes: 0
Views: 300
Reputation: 1198
and 3. Really you didn't. delete remove property from object or element from
array. You can't delete javascript object only remove
pointers to this object and wait for GC to clean memory. Replace
delete person;
with person = undefined;
to remove pointer
Person.prototype.constructor
is a real constructor where Backbone does it's own internal things. In the end it runs Person.prototype.initilalize
-- place to put your on_create logic
Upvotes: 1
Reputation: 18556
Basically as the delete operator works for arrays, if you had something like this fiddle. Check your js console, it throws an error, because the delete operator has removed the item from array.
-2 In Backbone.js you can treat the initialize -function like a constructor. You can use it to handle the parameters handed to the object at initialization in other that the default way.
For -3 I have no answer.
Hopefully this (partially) helped!
Upvotes: 1