JSFiddle - React, Tailwind, and code Playground
by juristr
HTML
<div id="output">
</div>
JavaScript
function print(msg){
document.getElementById('output').innerHTML = msg;
}
function sayHello(person){
if(person){
print(person.greet());
}else{
print('Hallo Unbekannter.');
}
}
var person = {
name: 'Rainer',
createGreetFn: function (){
return 'Hallo, I am ' + this.name;
},
child: {
}
};
sayHello(person);
// constructor function
function Animal(name){
this.name = name;
}
Animal.prototype.setChild = function(child){
this.child = child;
}
Animal.prototype.getChild = function(){
return this.child;
}
Animal.prototype.makeNoise = function(){
print('Miao');
}
var cat = new Animal('Cat');
cat.setChild(new Animal('Kitten'));
cat.getChild().makeNoise();