In the admin area I can edit the news (title, abstract, main text), this is all in 3 languages. I want to make it so that if some field has not changed, then we have not saved it (since there will be 9 fields, 3 for each language).

I create a prototype for the news:

var proto_content = { title:"", annon:"", text:"", len:new Array(6) }; 

then objects:

 var content_rus = Object.Create(proto_content); var content_eng = Object.Create(proto_content); var content_fra = Object.Create(proto_content); 

when filling:

 content_rus.len[0] = 1; content_eng.len[0] = 2; content_fra.len[0] = 3; 

at output:

 content_rus.len[0] -> 3 content_eng.len[0] -> 3 content_fra.len[0] -> 3 

Why property one on all objects? Tried new Object (proto_content) .... same story.

    1 answer 1

    The array in this case is passed by reference:

     [] == []; // false (разные инстансы) content_rus.len == content_eng.len; // true (инстанс один и тот же) 

    Personally, I would in this case use the constructor function:

     var Content = function Content () { this.title = ''; this.annon = ''; this.text = ''; this.len = new Array(6); }; var content_rus = new Content(); 
    • I found the problem in another, but I will use this method of creating a prototype. - Man