Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

34 lines (29 sloc) 1 KB
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Object-oriented JavaScript example</title>
</head>
<body>
<p>This example requires you to enter commands in your browser's JavaScript console (see <a href="https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_are_browser_developer_tools">What are browser developer tools</a> for more information).</p>
</body>
<script>
var person = {
name : {
first : 'Bob',
last : 'Smith'
},
age : 32,
gender : 'male',
interests : ['music', 'skiing'],
bio : function() { alert(this.name.first + ' ' + this.name.last + ' is ' + this.age + ' years old. He likes ' + this.interests[0] + ' and ' + this.interests[1] + '.');
},
greeting: function() {
alert('Hi! I\'m ' + this.name.first + '.');
}
};
var myDataName = 'height';
var myDataValue = '1.75m';
person[myDataName] = myDataValue;
</script>
</html>
You can’t perform that action at this time.