title: Does Buffer have a compare method?
body: <p>I am reading NodeJS tutorial and I have reached to <a href="http://www.tutorialspoint.com/nodejs/nodejs_buffers.htm" rel="nofollow">this</a> page.</p>
  
  <p>There is an example code for the compare method of Buffer objects:</p>
  
  <pre><code>var buffer1 = new Buffer('ABC');
  var buffer2 = new Buffer('ABCD');
  var result = buffer1.compare(buffer2);
  
  if(result &lt; 0) {
     console.log(buffer1 +" comes before " + buffer2);
  }else if(result == 0){
     console.log(buffer1 +" is same as " + buffer2);
  }else {
     console.log(buffer1 +" comes after " + buffer2);
  }
  </code></pre>
  
  <p>which throws this:</p>
  
  <blockquote>
    <p>Executing the program.... $node main.js</p>
    
    <p>/web/com/1460883529_55644/main.js:3 var result =
    buffer1.compare(buffer2);</p>
    
    <p>^ TypeError: Object ABC has no method 'compare'      at Object. (/web/com/1460883529_55644/main.js:3:22)</p>
    
    <p>at Module._compile (module.js:456:26)</p>
    
    <p>at Object.Module._extensions..js (module.js:474:10)</p>
    
    <p>at Module.load (module.js:356:32)</p>
    
    <p>at Function.Module._load (module.js:312:12)</p>
    
    <p>at Function.Module.runMain (module.js:497:10)</p>
    
    <p>at startup (node.js:119:16)</p>
    
    <p>at node.js:929:3</p>
  </blockquote>
  
  <p>It is strange that in the trace the object is called <code>ABC</code> and not <code>buffer1</code> and that there is no <code>compare</code> method according to the trace. The example which tried to clarify the <code>compare</code> method confused me. Can someone explain what happened here?</p>