Home  >  Article  >  Web Front-end  >  Example of how to create an object with JS

Example of how to create an object with JS

高洛峰
高洛峰Original
2016-12-07 15:56:171514browse

The example in this article describes how to create objects with JS. Share it with everyone for your reference, the details are as follows:

Writing 1:

<script>
var database = function () {
  function add(){
    console.info("add");
  }
  function queryAll(){
    console.info("queryAll");
  }
  /**
  带参数
  */
  function delById(id){
    console.info("delById:" +id);
  }
  return {
    add:add,
    queryAll:queryAll,
    delById:delById
  }
}();
database.add();
database.delById(34);
console.info(database);
</script>


URL HASH:

<script src="js/jquery-2.1.4.min.js"></script>
<script>
  function route() {
    var page = window.location.hash;
    console.info(page);
  }
  $(function() {
    $(window).bind("hashchange", route);
  })
</script>
<a href="#1">1</a>
<a href="#2">2</a>


We can use ajax to implement it when we click the connection by binding the hashchange event No refresh jump.

The above is the content of the writing examples of creating objects with JS. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


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