Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="http://stackoverflow.com/questions/28738177/why-doesnt-the-below-code-log-onetwo-as-expected/28738367#28738367">
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
function Buffer(initValue) {
    this.append(initValue);
}
Buffer.prototype = {
    items: [],
    append: function(str) {
        this.items[this.items.length] = str instanceof Buffer ?       str.toString() : str;
    return this;
},
    toString: function() {
        return this.items.join("");
    }
};
a = new Buffer("one");
a.append("two");
console.log(a.toString());
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
kursionpro
0viewers