Skip to content

Instantly share code, notes, and snippets.

@jocoonopa
Created November 17, 2013 00:03
Show Gist options
  • Save jocoonopa/7507112 to your computer and use it in GitHub Desktop.
Save jocoonopa/7507112 to your computer and use it in GitHub Desktop.
<!doctype html>
<html lang="zh-tw">
<head>
<meta charset="UTF-8">
<title>Javascript函式獨立性</title>
</head>
<body>
</body>
<script>
function Person ( name, age, sex ) {
this.name = name;
this.age = age;
this.sex = sex;
this.getInfo = function () {
console.log( this.name + this.age + this.sex );
};
}
var jocoonopa = new Person ( 'jocoonopa', 27, 'male' );
jocoonopa.getInfo();
function Animal ( name, sex, weight ) {
this.name = name;
this.sex = sex;
this.weight = weight;
}
var Piggy = new Animal ( '豬豬', '女生', '100公斤' );
jocoonopa.getInfo.call( Piggy );
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment