Home > Web Front-end > JS Tutorial > body text

Example of how to create an object with JS

高洛峰
Release: 2016-12-07 15:56:17
Original
1552 people have browsed it

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>
Copy after login


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>
Copy after login


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)!


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!