node.js - Why am I getting this error? r1= buf1.compare(buf2); ^ TypeError: Object Rahul has no method 'compare' -
/*this demo program campare buffers each other. expected output should numbers came know these equal or not. taking 3 buffer variables , storing data it. */ var buf1 = new buffer('rahul'); buffer contains rahul var buf2 = new buffer('kumar'); buffer contains kumar var buf3 = new buffer('rahul'); buffer contains rahul //now comparing these buffers each other r1= buf1.compare(buf2); r2= buf1.compare(buf3); r3= buf2.compare(buf3); //printing them console console.log(r1+ " " + r2 + " " + r3);
'compare' not prototype function. should used as:
buffer.compare(b1,b2)
added code example:
var b1=new buffer("a"); var b2=new buffer("b"); var r=buffer.compare(b1,b2); console.log(r);