Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

namespace in javascript

JavaScript does not provide namespace by default. However, we can replicate 
this functionality by making a global object which can contain all functions 
and variables.

Syntax:
    To initialise an empty namespace
     	var <namespace> = {}; 
    To access variables in the namespace
     	<namespace>.<identifier>
        
Example:
	var car = {
    	startEngine: function () {
        	console.log("Car started");             
    	}        
	}
  
	var bike = {
    	startEngine: function () {
        	console.log("Bike started");
    	}
	}
    
car.startEngine();
bike.startEngine();

Output:
	Car started
	Bike started
Comment

namespace javascript

// JavaScript does not provide namespace by default. 
// However, we can replicate this functionality by making 
// a global object which can contain all functions and 
// variables.
var car = {
    startEngine: function () {
        console.log("Car started");             
    }        
}
  
var bike = {
    startEngine: function () {
        console.log("Bike started");
    }
}
  
car.startEngine();
bike.startEngine();
Comment

PREVIOUS NEXT
Code Example
Javascript :: last value of array 
Javascript :: build angular project 
Javascript :: js int 
Javascript :: javascript expression interpolation 
Javascript :: stripe payment js 
Javascript :: date time react component 
Javascript :: js object 
Javascript :: break in javascript 
Javascript :: json to dart 
Javascript :: pretty print javascript 
Javascript :: how to declare 3d array in javascript 
Javascript :: React passing data fom child to parent component 
Javascript :: jfif to jpeg javascript 
Javascript :: what does the useReducer do in react 
Javascript :: react native better camera 
Javascript :: js string encode decode arabic 
Javascript :: calculate init code hash nodejs 
Javascript :: convert binary to string javascript 
Javascript :: jquery detach and remove 
Javascript :: how to write to and read from text files line by line using javascript 
Javascript :: neo4j get first 3 nodes 
Javascript :: stop monitorevents 
Javascript :: iterate over all check box in a div 
Javascript :: add variable to nth child jquery 
Javascript :: jquery select2 tab open 
Javascript :: node-google-spreadsheet color border 
Javascript :: how does URL.createObjectURl differ from fileReader 
Javascript :: How can I get or extract some string part from url jquery 
Javascript :: gatsbyjs shop flotiq 
Javascript :: jstree select all visible node only 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =