Home  >  Article  >  Web Front-end  >  Simple implementation method of javascript singleton pattern

Simple implementation method of javascript singleton pattern

PHPz
PHPzOriginal
2016-05-16 15:49:111211browse

The example in this article describes the simple implementation method of JavaScript singleton pattern. Share it with everyone for your reference. The specific implementation method is as follows:

function SingeInstance(){
  if(!SingeInstance._instance)
    SingeInstance._instance=this;
  return SingeInstance._instance;
}
var obj1=new SingeInstance();
var obj2=new SingeInstance();
console.log(obj1===obj2);   //true

I hope this article will be helpful to everyone’s JavaScript programming. For more related tutorials, please visit JavaScript Video Tutorial!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn