How to use JSHelper
The main purspose of this class (what follow the new sintax of ES6) is provide a list of methods to help developers to program faster. Besides this class add some new features to the prototypes of javascript to make easier to check the variables.
var testString = "text"; var testString2 = "Ostao je samo Ram"; var testArray = ["text", 2, 123, 4, "k", ""]; var testArray2 = []; var testObject = { name: function(){alert()}, inventedVar:null }; var leoIsset; var myfunction = "hello"; function hello(name, surname){ console.log("Hello " + name + " " + surname); } // lets try if(!jsHelper.isset(leoIsset) || !jsHelper.isset(testObject.inventedVar)){ console.log("These vars are null or undefined"); } if(jsHelper.isObject(testObject)){ console.log("This is a object"); } if(testArray2.empty()){ console.log("The array is empty :( "); } jsHelper.callFunctionByName(myfunction, [ "Djavole", "Moj" ]); console.log("TestString2 before: " + testString2); console.log("TestString2 after replacement: " + testString2.strReplaceAll(" ","")); console.log("TestString2 after replacement (only with 2): " + testString2.strReplaceAll(" ","",2)); if(testArray[5].empty()){ console.log("The string is empty :("); } if(testArray.in_array(123)){ console.log("Element found in the array :)"); } var stringFullTrim = testString2.fullTrim(); console.log(stringFullTrim);
<html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Come on little to remind</title> <script> window.onload = function(){ var newElement = {name:"a", text: "es un link", attrs: {href:"http://www.google.es",style:"color:red;"}}; jsHelper.createDOMElement(newElement,"box1"); }; </script> </head> <body> <div id ="box1"> </div> </body> </html>