On 3 Nov., 16:07, Sean Garner <
seanlgar...@gmail.com> wrote:
> Doesn't the `this` reserved word also contain the object. Initialisation
> then work on top of those values.
What I meant was the following functionality:
Class{id:'MyClass',
prototype: {
initialize:function(obj) {
if(obj.line) {
var parsedLine = MyExternalLibrary.parse(obj.line);
for(var prop in parsedLine) {
this[prop] = parsedLine[prop];
}
}
}
},
properties: {
// Some properties here ...
},
methods: {
}
});
Now I POST the JSON object {line:'Some external data to be parsed'} to
http://myserver/MyClass
The initialize method is called during the process of this POST
request, but I want to access the line property of the JSON object
that got posted. The "obj" parameters of "initialize" is undefined
when I use the HTTP interface. This came as a surprise to me, because
instantianting from the JS command line with exactly the same JSOn
object worked. "this.line" is also empty, so it seems that when
"initialize" is called, the data from the request has not been set and
is not given as the function parameter.
Is this by design and if yes, what are the reasons for the design?
I have now circumvented the problem by using the "onSave" prototype
function. Maybe you can add some more clarification to the
documentation in which order data is set.
Thanks to all for your replies.