| Autor | Zpráva | ||
|---|---|---|---|
| návštěvník Profil * |
#1 · Zasláno: 10. 5. 2015, 11:31:57
Zkouším si udělat vlastní (rychlejší) funkci na vygenerování náhodného čísla. Podstata: iniciovat pole funkcí Springy.Random.Initiate() a pak jen volat třeba Springy.Random() ...
Mám toto: var Random = Springy.Random = Springy.Random = function(params) {
var random = [];
var initiate = function (){
for (var i=0; i<1000; i++)
{
random[i] = Math.round(10.0 * (Math.random() - 0.5));
}
}
console.log(random);
};A když zavolám Springy.Random.initiate(); // initiate random array |
||
| Kubo2 Profil |
#2 · Zasláno: 10. 5. 2015, 12:49:56
návštěvník:
Volanie Springy.Random.initiate() musí skončiť chybou, pretože initiate je jednoducho lokálna premenná vnútri funkcie Springy.Random(). Musíš iniciovať vlastnosť objektu Springy.Random.initiate.
|
||
| návštěvník Profil * |
#3 · Zasláno: 10. 5. 2015, 12:59:25 · Upravil/a: návštěvník
Tuto funkci jsem vymazal, ale mám jinou:
var Springy = {};
var Graph = Springy.Graph = function(params) {
this.nodeSet = {};
this.nodeLabels = [];
this.nodeIds = [];
this.images = [];
this.nodes = [];
this.edges = [];
this.adjacency = {};
this.imageType = params.imageType !== undefined ? params.imageType : ".jpg";
this.imagePath = params.imagePath !== undefined ? params.imagePath : "";
this.nextNodeId = -1;
this.nextEdgeId = 0;
this.eventListeners = [];
this.initAllNodesCompleted = false;
this.totalNodes = 0;
};
Springy.Graph.getTotalNodes = function(){
return !this.initAllNodesCompleted ? 0 : this.totalNodes;
}console.log(Springy.Graph.getTotalNodes()); je to správně? Když změním tu funkci: Springy.Graph.getTotalNodes = function(){
console.log(Springy.Graph.totalNodes);
return Springy.Graph.totalNodes;
} Springy.Graph.getTotalNodes = function(){
console.log(Springy.totalNodes);
return Springy.totalNodes;
} Springy.Graph.getTotalNodes = function(){
console.log(this.totalNodes);
return this.totalNodes;
} |
||
| Radek9 Profil |
návštěvník:
Springy.Graph je konstruktor, ne? A to getTotalNodes má být, hádám, jeho metoda, správně? Takže ji musíš přidat na prototyp a volat z instance:
Springy.Graph.prototype.getTotalNodes = function(){
return !this.initAllNodesCompleted ? 0 : this.totalNodes;
};
var graph = new Springy.Graph(params);
graph.getTotalNodes(); |
||
| návštěvník Profil * |
#5 · Zasláno: 10. 5. 2015, 14:41:35
Když vono je to složitější. Ten kód je z knihovny springy.js:
http://getspringy.com/springy.js http://getspringy.com/demo.html Ten můj tam nenajdeš, ale vidíš tam jak to vypadá. Tedy kolem řádku 55 jsem udělal úpravy. Pak je tam druhý soubor: http://getspringy.com/springyui.js kde je třeba najít řádek s textem "// First time seeing an image with this src address" odsud potřebuju provést volání. Kontext: Čtvrtý argument funkce Springy.Renderer je: (drawNode function definition) -> (drawText function definition) -> odsud chci provést volání Springy.Renderer je definovaný v spring.js na ř. 645: var Renderer = Springy.Renderer = function(layout, clear, drawEdge, drawNode, onRenderStop, onRenderStart) {
this.layout = layout;
this.clear = clear;
this.drawEdge = drawEdge;
this.drawNode = drawNode;
this.onRenderStop = onRenderStop;
this.onRenderStart = onRenderStart;
this.layout.graph.addGraphListener(this);
}Celou věc souštím ze simple.html: jQuery(function(){
var springy = jQuery('#springydemo').springy({
graph: graph
});
});Pak se tam volá Springy.requestAnimationFrame // springyui.js Takže není lehké se v tom vyznat a já nevím jak to rozjet. |
||
| návštěvník Profil * |
#6 · Zasláno: 10. 5. 2015, 16:00:44
Už jsem na to přišel. stačí tam (javascriptui.js) napsat
graph.getTotalNodes() protože graph už je nastavený. Nevím sice kde ale je to tam. Asi hned na začátku jQuery.fn.springy = function(params) {
...
params.graph = this.graph = params.graph || new Springy.Graph();
...A vlastně bych ani tu funkci nemusel vytvářet, protože k tomu se dá dostat přímo. Tak co myslíš mám tam tu funkci nechat nebo smazat? graph.totalNodes vrátí to samé |
||
|
Časová prodleva: 11 let
|
|||
0