JavaScript: Looping through a prototype function's variable -


I am trying to do something like this:

  var MyFunction = function (name ) {Var handles = this; the handle. Name = name; } Var LoopThroughNames = function () {for (name in MyFunction) {// it does not work console.log (name); }} Var Handle 1 = New MyFunction ("Hello World!"); Var Handle 2 = New MyFunction ("Test"); LoopThroughNames ();  

Sorry for the lack of code tags, I am on my phone.

You are confusing class with this example:
Name Property Example: has been created with new ones.
The function MyFunction itself is not affected by those changes, therefore, myfunction does not have any assets.

EDIT: After the idea of ​​zoommands, if you want to keep all the examples prepared, you can put them in an array and why this array is stored as my simplified property Do not. After some name changes and so on, I suggest:

  function myclass (name) {this.name = name; MyClass.instances.push (this); } MyClass.instances = []; Function printInstancesProperty (targetClass, propName) {for (var i = 0; i & lt; targetClass.instances.length; i ++) {// This work var example = targetClass.instances [i]; Console.log (example [propName]); }} Var Handle 1 = New MyClass ("Hello World!"); Var Handle 2 = New Mylly ("Test"); PrintInstancesProperty (MyClass, 'name');  

The result is expected:

  "Hello World!" "Test"  


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -