// backbone.js example of modal
var alert = function (str) {
var st = document.createTextNode(str);
var p = document.createElement('p');
p.appendChild(st);
document.querySelector('body').appendChild(p);
}
// first using javascript
var Person = function (config) {
this.name = config.name;
this.age = config.age;
this.occupation = config.occupation;
}
Person.prototype.work = function () {
return this.name + ' is working.';
}
var person = new Person({
name: "deepak sisodiya",
age: 22,
occupation: "Software engineer"
})
alert(person.name)
alert(person.age)
alert(person.occupation)
alert(person.work())
// using backbone.js
var Person2 = Backbone.Model.extend({
defaults: {
name: 'Guest User',
age: 23,
occupation: 'Worker'
},
work: function () {
return this.get('name') + ' is working.';
}
});
var person = new Person2;
alert(person.get('name'))
alert(person.get('age'))
alert(person.get('occupation'))
person.set('name', 'Taroon Tyagi')// will update the name
person.set('age', 26) // will update the age
person.set('occupation', 'Graphics Designer')// will update occupation
// you can update the values in just on go
person.set({name:"Taroon Tyagi", age: 26, occupation: "Graphics Designer"})
alert(person.get('name'))
alert(person.get('age'))
alert(person.get('occupation'))
var person3 = new Person2({name:"deepak sisodiya", age: 22, occupation: "Graphics Designer"})
alert(person3.get('name'))
alert(person3.get('age'))
alert(person3.get('occupation'))
alert(person.get('name'))
alert(person.get('age'))
alert(person.get('occupation'))
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.