【JS】利用函数构建对象

Osinghong2周前 (04-14)成果展示33
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>d24c04429</title>
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		
	</head>
	<body>
		<script>
			function Student(name, age) {
				this.name = name;
				this.age = age;
				this.introduce = function() {
					console.log("大家好,我叫" + this.name + ",今年" + this.age + "岁");
				};
			}
			var stu1 = new Student("欧永鸿", 18);
				stu1.introduce();
		</script>
	</body>
</html>


打赏
分享给朋友:

相关文章

【H5】ul,li练习

练习一:<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <titl...

【H5】小米导航栏

<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta nam...

【JS】递增和递减运算符

<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>...

【JS】For语句

<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>...

【JS】For语句进阶

<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>...

【JS】循环嵌套

<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>...