It creates a bunch of objects. How to make, that created objects could inherit through prototype?

<script> function Red() { this.pl = 'polska'; this.bel = 'belarus' } Red.prototype.country = function () { return this.bel } function Class(dz) { //Red.call(this); var obj = {}; obj.value = dz; // свойство obj.some_method = function () { // метод console.log('some_method invoked'); } return obj; } // Class.prototype=new Red; var obj1 = Class('c'); var obj2 = Class('m'); alert( obj1.pl + ':' + obj2.bel) </script> 
  • so what? var obj = {}; obj .__ proto__ = new Red (); if not, describe the problem in more detail - Specter
  • Yes, but for all browsers - zloctb

1 answer 1

You have commented Red.call(this); trying to do something like that?

 var obj = {}; Red.apply(obj); 

But since there is no access to the prototype, then why not just:

 var obj = new Red(); 
  • Specter everything turned out . Thank you - zloctb