Javascript define : Miscellaneous Functions : PHP functions in JavaScript JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » PHP functions in JavaScript » Miscellaneous Functions »

 

Javascript define


Define a new constant
Example 1

Running
1.define('IMAGINARY_CONSTANT1', 'imaginary_value1');

Could return
1.true
function define(name, value) {
    // Define a new constant  
    // 
    // version: 812.316
    // discuss at: http://phpjs.org/functions/define
    // +   original by: Paulo Ricardo F. Santos
    // *     example 1: define('IMAGINARY_CONSTANT1', 'imaginary_value1');
    // *     returns 1: true
    
    if (/boolean|number|null|string/.test(typeof value) !== true) {
        return false;
    }
    
    return (window[name] = value) !== undefined;
}


HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo PHP functions in JavaScript
» Miscellaneous Functions