1
我嘗試的NodeJSES6類和擴展內置的緩衝
TypeError: Buffer2.from(...).slice2 is not a function
延長緩衝區對象,但它看起來就像我從來無法與新類
overwite我怎樣才能讓Buffer2.from回報BUFFER2?
ES6類和extends關鍵字
反正沒有更好的做一個完全新的類呢?
class Buffer2 extends Buffer
{
constructor(obj, encoding)
{
console.log('Buffer2::constructor');
super(obj, encoding);
return this;
}
slice(start, end)
{
console.log('Buffer2::slice');
return this.slice(start, end)
}
slice2(start, length)
{
console.log('Buffer2::slice2');
return this.slice(start, start + length)
}
static from(obj, encoding)
{
console.log('Buffer2::from');
return new Buffer2(obj, encoding);
}
}
Buffer2.prototype.slice = function (start, end)
{
console.log('Buffer2::slice');
return this.slice(start, end)
}
Buffer2.prototype.slice2 = function (start, length)
{
return this.slice(start, start + length)
}
console.log(Buffer2, Buffer2.from('7E1D2C', 'hex').slice2(0, 1));