JSFiddle - React, Tailwind, and code Playground

by Abdul Ahmad

JavaScript

function fruit() {
	var self = this;
  self.fruitname = 'apple';
  console.log(self);
  return self;
}

function run(fruit) {
	alert(fruit.fruitname);
}

run(fruit());
run(new fruit());

function fruit(args) {
  if (typeof this === 'undefined' || !(this instanceof fruit)) {
  	return new fruit(args);
  }
	console.log(this);
  this.fruitname = args;
}

function run(fruit) {
	alert(fruit.fruitname);
}

run(fruit('apple'));