【发布时间】:2019-02-26 15:31:41
【问题描述】:
我有问题。 当我从一个对象实例化时,它不会返回构造函数的值。 ..................................................... ..................................................... ..................................................... ………… ..................................................... ..................................................... ..................................................... ..........
//Main Branch
var Creatures = function () {
function Creatures(name,alive) {
this.name = name;
this.alive = alive;
}
function Creatuers(name,alive,sleep) {
this.name = name;
this.alive = alive;
this.sleep = sleep;
}
};
var Beast = function () {
function breathe() {
return true;
}
this.__proto__ = new Creatures;
};
var Mammals = function () {
this.numberOfBeads = "i am numberOfBeads from Mammals";
this.__proto__ = new Beast;
};
//Mammals Branch
var Humans = function () {
function thinking(){
return true;
}
this.love = "i am love from humans";
this.__proto__ = new Mammals;
};
var Animals = function () {
this.instinct = "i am Animals from Animals";
this.__proto__ = new Mammals;
};
var Plants = function () {
this.color = "i am color from Plants";
function grown() {
return true;
}
this.__proto__ = new Creatures;
};
var Trees = function () {
this.height = "i am height from Trees";
this.__proto__ = new Plants;
};
var Flowers = function () {
this.smell = "i am smell from Flowers";
this.__proto__ = new Plants;
};
var Grasses = function () {
this.color = "i am color from Grasses";
this.__proto__ = new Plants;
};
var obj2 = new Creatures("ali",true);
alert(obj2.name);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Index</title>
</head>
<body>
<script src="sampleObject1.js"></script>
<script src="sampleObject2.js"></script>
</body>
</html>
【问题讨论】:
-
您尝试做的事情是晦涩难懂的。你能解释一下你的意图(并将你的代码减少到minimal reproducible example)吗?
标签: javascript html oop prototype