function Test(){ //... } Test.prototype = { data: undefined, working: null, // массив с инстенсами collectData: function(){ this.data = 'data'; // здесь я собираю данные }, run: function(){ // здесь прохожу по массиву инстенсов var length = this.working.length, item = undefined; for(var i = 0; i < length; i++){ item = this.working[i]; item.one.call(this); // и передаю им this в качестве контекста } } } /** * И все это сделано для того, * чтобы в объектах ниже я мог обращаться * к свойству data инстенса var test = new Test(); * как к своему... * * Делают так в js? Под "так" я подразумеваю * вызов методов из массива в инстенсе test * с передачей в эти методы себя в качестве * контекста? * И если так в js делают, то как это с точки * зрения ООП? */ var Obj1 = { one: function(){ console.log('obj1', this.data); }, two: function(){ //... } } var Obj2 = { one: function(){ console.log('obj2', this.data); }, two: function(){ //... } } var test = new Test(); test.working([new obj1(), new obj2()]); test.collectData(); test.run(); I have a Test object that is designed to process data that it receives by reference. It receives an unformatted string that needs to be very richly formatted, and for this I still have objects, in my case obj1 and obj2, each of which performs the necessary actions with the data.
And the question is - is it possible to do this in js and is this approach beyond the scope of the PLO?