0

Hellow guys am a newbie in javascript .I have seen some code like this ..

function f() {

    var model = this.model.attributes;

    var data = {
        path: Config.baseUrl,
        lang: url.segment(1),
        id: model['id'],
        date: model['date'],
        views: model['views'],
        author: model['author'],
        authorName: model['authorName'],
        question: model['question'],
        answer: model['answer'],
        rate: model['rate'],
        _ : _,
        S: S,
        moment: moment
    };

I just need to know model['id'] model['views'] etc etc ..i just need to know the use of id,date,views author here .In php its like array and key but is it the same concept in jaavascript too ..Any help would be greatly appreciated thanks .:)

william
  • 33
  • 5
  • 1
    model['date'] is like writing model.date : it's written either object['property'] or object.property – frenchie Feb 07 '14 at 14:17
  • 1
    Its called [__Bracket notation__](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Member_Operators#Bracket_notation) – Satpal Feb 07 '14 at 14:18

2 Answers2

0

With views: model['views'],

You declare views equal to the views attribute of the model element.

And so on with the others

laaposto
  • 11,835
  • 15
  • 54
  • 71
0

The use of this is one thing to watch out for. The model variable inside f is being assigned to a model property outside the function. So look for model in the outer object to figure out where that stuff is coming from.

beautifulcoder
  • 10,832
  • 3
  • 19
  • 29