0

I came from Java object model and new to JSON. Trying to understand how true is JSON object model. Does it provide implement and extend ability?

If no, then how would I achieve the similar object model?

I did try to google about it but could not find anything specific.

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
Himanshu Yadav
  • 13,315
  • 46
  • 162
  • 291
  • 1
    JSON is just a *string representation* of data. JSON just so happens to be valid JavaScript syntax. There is no such thing as a "JSON object". You're talking about a "JavaScript object". – gen_Eric Jan 14 '13 at 18:52

2 Answers2

1

I have a feeling that what you meant to ask is " Trying to understand how true is JavaScript object model". JSON representation of any javascript object would simply be a transcription of that object if you will. So anything having to do with OO structure would have to be dealt with in JavaScript rather than JSON itself. This question would be a good lead in to representing your object in JSON format.

PS: If you're comfortable with java OO model, playground at typescript might be a good 'visualizer' for you. On the left side panel you can create something very close to an object you'd create in java (play with inheritance, etc.) and on the right side you'll see it's javascript 'translation'. Very clean, very straight forward 'by the book'.

Community
  • 1
  • 1
vector
  • 7,334
  • 8
  • 52
  • 80
  • So there is no true object representation in Javascript? – Himanshu Yadav Jan 14 '13 at 20:07
  • Not really - if you expect it to be like java. The hardest thing is to 'let JS be JS' when you're diving into it coming from a Java background. Java OO preconceptions can be very frustrating. – vector Jan 14 '13 at 20:18
0

javascript doesn't have a implements or extends method built in like java. You can construct ways to mock that behavior if you want. There are mvc libraries out there that offer these desired behavior, for example mvc library backbone's model class has a extends functionalites. Google, javascript inheritance for more info.

dchhetri
  • 6,926
  • 4
  • 43
  • 56