score:0
Accepted answer
i know nothing about your domain, but here's an example of what you could do:
//define the 'charts' module
var charts = (function () {
//chart constructor
function chart() {
}
chart.prototype = {
constructor: chart,
//public chart api
width: function () { /*...*/ }
};
//public module members
return {
chart: chart
};
})();
//using it
var chart = new charts.chart();
if you need priviledged members, you can always rely on closures, but i do not recommend it because it's less memory-efficient (instances aren't sharing functions).
e.g.
function chart(width) {
var _width = width; //private var
//priviledged function
this.width = function () { return _width ; };
}
score:0
in the below code ,am not using prototype as you used. is there any difference between both the codes.any way both will return same object.is there any difference in handling objects
var charts = (function () {
//chart constructor
function chart() {
console.log(this.width())
}
chart.constructor = function() {
}
chart.width = function(){
}
};
//public module members
return chart
})();
//using it
var chart = new charts.chart();
Source: stackoverflow.com
Related Query
- Closure or prototype model for charting library
- Comparision for D3.js vs zingChart library for visualizations and charting
- Javascript or other charting library for geodata
- HTML5 canvas alternatives for d3.js, graph visualization library
- How to set the Origin (drag.origin) for drag behavior in d3 JavaScript library
- Suitable library for combining with D3js , to allowing drawing to webgl (2D)
- Mix bar and line charts with Rickshaw (d3 based graphing library for js)
- JavaScript dynamic graph library for displaying "big-data"?
- Using a d3.js based charting library
- Convert R dataframe into tough JSON list of lists for d3.hierarchy model
- Any chart library for funnel chart instead of highchart?
- JavaScript library more efficient than Rickshaw for realtime visualizations
- Create an array from csv for use with D3.js library
- Library for creating scatter plot charts with quadrants
- Query SQL data in Flask to use for charting without using the app.route decorator
- Want to use chart which gives you difference of something in charting library javascript
- Referencing JavaScript library in GWT for JavaScript Code
- TypeScript build error for Ionic application using C3/D3 graph library
- rendering d3.js library visualizations for colorbrewer
- Data model for creating a radial bar chart with d3js
- D3.js: How to get the computed width and height for an arbitrary element?
- A good book for learning D3.js
- Javascript library d3 call function
- What is the d3.js v4.0 equivalent for d3.scale.category10()?
- Appending multiple non-nested elements for each data member with D3.js
- How to set text color for my d3 chart title?
- How to disable double click zoom for d3.behavior.zoom?
- How do I display dates on the x-axis for nvd3 / d3.js?
- Learning d3.js for data visualisation
- Styles in component for D3.js do not show in angular 2
More Query from same tag
- Adding event listeners into dynamically created elements
- How do I add labels to d3.js force bubble chart
- Zooming bar-graph with d3.js
- Control multi line spreading of x-axis tick in billboard.js
- SVG datum as a JSON object
- Using D3 in Modular ES6
- d3.js map chart draw rectangle
- How to make 2 color represent positive and negative word cloud in d3.js from csv
- How to group labels in Timeline chart in JS
- Optimizing javascript d3 statement
- D3: ordinal scale returning undefined in part of its range
- d3.js transition end event
- D3 v6 how to join correctly?
- Change Legends and Node to an circle image
- d3 v4 js : attribute error
- d3 graph - How do I make the JS get the JSON from PHP script and then select axes and plot?
- Drew a straight line, but it is crooked d3
- How to Grow the Arc On Mouseover in D3.js and HTML
- Populating D3 chart with external JSON file
- How to dynamically add,edit,remove nodes to tree in d3.js tree
- How to adjust svg height within table cell?
- Bubble highlight feature in d3js bubble chart
- Can 'click' change an attribute for a nested group?
- Centering multiple line wrapping
- Create rect with blurred stroke in svg using d3.js
- D3 Line Chart Show/Hide Element, Variable Not Defined Error?
- d3 choropleth map having problems with filling colors
- How to implement a smooth transition when new bands are created in d3?
- How to implement multiple trees with different orientations in D3.js v4?
- D3.js Sankey diagram with particles