Home > Article > Web Front-end > Example of how to create an object with JS
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)!