I really tried hard to find very simple and working example (e.g. on MDN), but it makes me mad. I can not simply figure out, where I do mistake. I would like to have an ancestor of the Array object. Here is sample.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Fiddling</title>
<script>
function Synthese() {
//Array.call(this);
//Synthese.prototype = Object.create(Array.prototype);
//Synthese.prototype.constructor = Synthese;
this.prototype = Object.create(Array);
//this.prototype.constructor = this;
this.Make = function () {
result = "";
for (i=0; i<this.length; i++){
result = result + this[i] + ".";
}
return result;
}
}
var A = new Array();
A.push("A"); //OK
var S = new Synthese();
S.push("A"); //fails
S.push("B");
alert(S.Make());
</script>
</head>
<body>
</body>
</html>
How make Synthese be child of Array? S.push("A"); never executes