I am trying to start learning OO JS and have one quick question (i have condensed my actual issue for ease).
Basically, the following alert just returns [Object object], i want it to return 3 different alert boxes
<body>
<div id="bob">
<div>f</div>
<div>t</div>
<div>q</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
var Person = {
name: $('#bob div').each(
function(){
$(this).text();
}
)
}
alert(Person.name);
});
</script>
</body>
Any guidance much appreciated.
Adi.
Perhaps you can do something like this:
Note, though, that in JavaScript names that start with a capital (in this case,
Person) are usually reserved for constructor functions (i.e. functions that are used to create new instances using thenewkeyword). These are usually called types, because the name classes would be misleading.If you want to make your code truly Object Oriented, you could try something like this:
Recommended reading: