Build component with javascript file

Posted on 2015-04-13 07:22:02

Have a friend once asked me How to pack a javascript file like a component for use in your projects ? I will share with everyone How to build a file component javascript and use it in project. Content of  file member.js
var Member = { add: function() { alert('You have just call to add function with component file member js'); }, delete: function() { alert('Deleted success'); }, }
Content of file index.php
<html> <head> <script src="//" type="text/javascript"></script> <script src="member.js" type="text/javascript"></script> <script language="javascript"> $( document ).ready(function() { Member.add();// demo function add have been called from component file member.js Member.delete();// demo function delete have been called from component file member.js }); </script> </head> <body> </body> </html>
You can download all file at demo_componentJS   Read more guides at here