JSON Object Code Example
The first example is to demonstrate the power and the accessibility JSON offers to developers.
This is a JavaScript code designed to make things easier for the -new to JSON- developer:
function User(fName, lName, age, friends)
{
var UserObject = {
FirstName: fName,
LastName: lName,
Age: age,
Friends: [],
IsUnderAge: function()
{
return this.Age > 21 ? true : false;
}
};
var FriendsCounter = 0;
for (var frnd in friends)
{
UserObject.Friends[FriendsCounter] = friends[frnd];
FriendsCounter++;
}
return UserObject;
}
This is the constructor. Same as in every OOP language, each object needs to have constructors.
Now, lets say I let a user named Igor fill an information form containing the following fields:
function createUser()
{
var IgorsFriends = [];
IgorsFriends[0] = new User("Uri", "GamingTech", 29, []);
IgorsFriends[1] = new User("Sergey", "GamingTech", 35, [
new User("Noam", "GamingTech", 27, [])
]);
var Igor = new User("Igor", "GamingTech", 33, IgorsFriends);
}
Good luck,
Elad Shalom,
CTO at ITweetLive.com
This is a JavaScript code designed to make things easier for the -new to JSON- developer:
function User(fName, lName, age, friends)
{
var UserObject = {
FirstName: fName,
LastName: lName,
Age: age,
Friends: [],
IsUnderAge: function()
{
return this.Age > 21 ? true : false;
}
};
var FriendsCounter = 0;
for (var frnd in friends)
{
UserObject.Friends[FriendsCounter] = friends[frnd];
FriendsCounter++;
}
return UserObject;
}
This is the constructor. Same as in every OOP language, each object needs to have constructors.
Now, lets say I let a user named Igor fill an information form containing the following fields:
- First Name
- Last Name
- Age
- Friends - each friend will have the same fields.
function createUser()
{
var IgorsFriends = [];
IgorsFriends[0] = new User("Uri", "GamingTech", 29, []);
IgorsFriends[1] = new User("Sergey", "GamingTech", 35, [
new User("Noam", "GamingTech", 27, [])
]);
var Igor = new User("Igor", "GamingTech", 33, IgorsFriends);
}
The outcome of this function will be a varaible named Igor which will have the following attributes:
- First Name
- Last Name
- Age
The following methods:
- IsUnderAge
And the following Arrays:
- Friends - which will contain list of friends as User objects.
Good luck,
Elad Shalom,
CTO at ITweetLive.com
Finally i have found something that i can understand. Thank you!
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteReally Usefull.
ReplyDeletenike free, louis vuitton outlet online, chanel handbags, oakley sunglasses, burberry outlet online, air max, tiffany and co, ray ban, prada outlet, ray ban sunglasses, burberry outlet online, louboutin, longchamp outlet, louboutin, coach outlet store, polo ralph lauren outlet, oakley sunglasses, jordan shoes, oakley sunglasses, coach factory outlet, coach outlet, nike shoes, michael kors outlet, gucci outlet, coach purses, coach factory, tory burch outlet, prada handbags, oakley sunglasses, toms shoes, louis vuitton handbags, true religion jeans, true religion outlet, kate spade outlet, ray ban sunglasses, true religion, polo ralph lauren, nike air max, oakley sunglasses, michael kors outlet
ReplyDeletelouis vuitton handbags
ReplyDeletelouis vuitton outlet
coach outlet store online
air max 90
louis vuitton
fitflop sandals
michael kors outlet
nike air force 1
jordan 11s
cheap oakley sunglasses
ray ban sunglasses
gucci outlet
coach outlet
nike trainers
coach factory outlet
hollister clothing
michael kors outlet online
christian louboutin sale
kevin durant shoes
abercrombie
coach factory outlet
nike air max
nike air jordan
marc jacobs
polo ralph shirts
ray ban sunglasses outlet
ralph lauren sale
louis vuitton handbags
louis vuitton outlet
louis vuitton
mont blanc pens
tory burch outlet
ray-ban sunglasses
kate spade
tiffany outlet
michael kors outlet
michael kors handbags
replica watches
michael kors handbags
michael kors outlet
20165.23wengdongdong
jordan shoes
ReplyDeleterolex replica watches
fitflops sale clearance
canada goose sale
christian louboutin uk
canada goose uk
louis vuitton purse
reebok outlet store
lacoste shoes
north face jackets
nike air max 90
coach outlet online
air jordan shoes
ray ban sunglasses outlet
longchamp bag
ugg boots
instyler max
true religion jeans outlet
oakley sunglasses outlet
louis vuitton handbags
canada goose sale
moncler uk
coach outlet online
cheap ray bans
michael kors handbags
dolce and gabbana outlet online
jordan pas cher
longchamp outlet store
babyliss hair dryer
nike store uk
ecco outlet
kate spade bags
polo ralph lauren
cheap ray ban sunglasses
20160722caiyan
kyrie 4
ReplyDeletekyrie 4 shoes
moncler
adidas stan smith
fila shoes
jordan 6
michael kors outlet online
cheap jordans
timberland boots
jordan shoes