js多态

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
<script type="text/javascript">
	function Dog()
	{
		this.eat=function()
		{
               console.log(" 狗吃东西");
		}
	}
	function Cat()
	{
		this.eat=function()
		{
			console.log("猫吃东西");
		}
	}
	function feed(animal)
	{
		animal.eat();
	}
	let dog=new Dog();
	feed(dog);
	let cat=new Cat();
	feed(cat);
</script>
</body>
</html>

在这里插入图片描述

posted @ 2020-09-02 00:43  贵哥的编程之路  阅读(5)  评论(0)    收藏  举报