How do I inherit methods from one prototype to another using the 'util' module from Node.js?

3

I was watching the video of a guy explaining Node.js events and in the end he makes a small module using util.inherit to inherit from one prototype builder to another. Although I know the syntax of call and have gotten a sense of the util.inherit method in the DOCS API , I could not catch the semantics of the code in general.

Module Builder

var EventEmitter - require('events').EventEmitter;
var inherits = require('util').inherits;

function FireDetector(){
    EventEmitter.call(this);
}

inherits(FireDetector, EventEmitter);

FireDetector.prototype.smoke = function(amount){
    if(amount > 0.5) {
        this.emit('fire').
    }
}

module.exports = FireDetector;

Example use of the module (only as a bonus)

var FireDetector = require('./firedetector');

fireDetector = new FireDetector();

fireDetector.on('fire', function() {
    console.log('fire fire fire');
});
    
asked by anonymous 13.01.2015 / 04:05

1 answer

3

Maybe your question is clear if you take a look at the Node / useful in GitHub .

In the background is a shortcut to import / inherit from an existing prototype. The source code is:

exports.inherits = function(ctor, superCtor) {
  ctor.super_ = superCtor;
  ctor.prototype = Object.create(superCtor.prototype, {
    constructor: {
      value: ctor,
      enumerable: false,
      writable: true,
      configurable: true
    }
  });
};

That is:

FireDetector.super_ = EventEmitter
FireDetector.prototype = Object.create(EventEmitter.prototype, {
    constructor: {
      value: FireDetector,
      enumerable: false,
      writable: true,
      configurable: true
    }
});
    
13.01.2015 / 08:00
___ ___ erkimt Specifying the search engines update an HTML document? ______ qstntxt ___

According to MDN using the %code% tag with attribute %code% %code% , allows search engines to know the date the document was created, and then displays this information in the Rich Snippet of the searches.

Is it possible to indicate the update date for it?

    
______ azszpr332568 ___

You can build your %code% by using the %code% tag to tell %code% that you want your content to be re-indexed, hourly, every day, or weekly for example.

Here you can see the complete and recommended protocol for you to build your %code% , notice that you can determine how regularly your content is reindexed: link

The frequency with which the page changes. This value provides general information for search engines and may not match the frequency of page indexing. Valid values are:

  • always
  • hourly
  • daily
  • weekly
  • monthly
  • yearly
  • never

The "always" value should be used to describe documents that always change when accessed. The value "never" should be used to describe the archived URLs.

Note that the value of this tag is considered a %code% and not a command.

Although you can not be totally sure that Google will consider this tag to reindex its contents %code% or %code% for example

  

"If the site pages are properly linked, the normal   Web crawlers can detect most of your   site. ", but" The use of the sitemap does not guarantee that all items in it   will be crawled and indexed because Google processes are   based complex algorithms to program the tracking. However, the   sitemap benefits the site in most cases, and you will never be   penalized for using it. "

Source: link

Otherwise, you will not be able to completely stop %code% , in a case of urgency you can manually request the reindexing of a URL. For example if you make a security update on the contacts page you can ask Google to do a reindexing of your page. Here you can learn more about this: link

To manually add a URL (search tb "Fetch as Google") : link

To index by Search Console:

YoucanstillrequesttoreindextheentiresitethroughtheSerchConsole!

    
___ Error when another class calls method of an Activity