Jump to content

Ramu26

Members
  • Posts

    15
  • Joined

  • Last visited

Ramu26's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. Correct, but, My question how can Objects be created without classes. That eventually means, the language internal has class, but, not exposed as language feature right ?
  2. Hi All, When we create a object and invoke a method on it. 1. Instance will be searched and then the prototype and so on till the Object prototype; when will the Global object be searched ? also what is the role of activation Object ? My understanding is. 1. when we invoke a object Activation object will be created which will have references to prototype and constructor 2. prototype chain continues to supertype up till Object as every object extends Object 3. Finally Object prototype will have refrences to Global/Window Object right So is the sequence, activation Object Of instance ->supertype prototype -> Object prototype -> Global Window Object type correct ? Thank, Chandra
  3. If I have only shared information in prototype and specifics at the instance level, I can choose to use Supertype.call() to inherit the specifics/instance level information. In that case, I can directly reference the prototype right ?
  4. even though var creates a private variable it should be part of the object and when we say o.getPersonProperty(). still the variable declared using var should be accessible through "this" right ? because "this" refers to same function in which var is used for defining the property. Why is it treating them differently ?
  5. Hi Foxy Mod, Thanks, Yes, if we mark something as "var" it is private and can't be accessed outside the function,so based on this behavior in 3 is correct. Now, based on your explanation we are assigning "getPersonProperty" on the current object in 1 so this also works. Now let us consider #2 here it is same as #1 but I have referenced the variable also with "this", it gives me "undefined", is it adding/overwriting new "this.personProperty" at runtime on the object being invoked. How does it work for #1, but #2. Thanks
  6. That means we don't have aggregation/Isa/extends relationship right ?
  7. Hi, do we have Isa(aggregation) and Hasa(composition) relationships in JS?though instanceof check passes for all the types of inheritance;they are just changing the references of prototype and shadowthe instance variables, I think instanceof is implemented to return true with references only, instead of really creating the required Object.This is still fine. But, do we have Hasa relationship ? for Hasa we can do var o = {};function f(){var hasa=o;}but samething is also done for prototype inheritance, then what we have is only Hasa and instanceof is implemented to return true right ?
  8. Hi All, Why there are no classes in JS ? if there are no classes then how are we creating function objects examplefunction Person(){}var p = new Person(); we are instantiating a function instead of class, how can this happen and how is instanceof check passing if there are no classes ?If there were their then data and accessor properties could have been applied only once instead of defining them every time when the Object is created right?for example:var o={};Object.defineProperty(o,name,{ value : "testingNameProperty", writeable: false});if had class we could have configured this directly on class instead of object "o", which makes more sense,In this case, we have to define this every time the object is created.
  9. Hi, Prototypal inheritance advocates Approach: 2, where we wrap the parent prototype with new object, augment the constructor and then assign it to subType. However, in Approach : 1 I havedirectly assigned the prototype both instanceof and prototype checks have passed. function Person(){}Person.prototype.sayHi=function(){ return "hi";}function SubPerson(){}//Approach : 1 directly assign the prototypeSubPerson.prototype= Person.prototype; //Approach : 2 wrap it with the other object//var newObject= Object.create(Person.prototype); //newObject.constructor=SubPerson;//SubPerson.prototype=newObject;var subPersonInstance= new SubPerson();console.log( (subPersonInstance instanceof SubPerson) +" "+ (subPersonInstance instanceof Person));console.log( (SubPerson.prototype.isPrototypeOf(subPersonInstance)) +" "+ (Person.prototype.isPrototypeOf(subPersonInstance))); In that case, we can go by Approach : 1 right ? why to wrap it with new Object.Thanks
  10. Hi All, In the code below, function Person(){ var personProperty="personPropertyValue"; //1 this works fine this.getPersonProperty=function(){ return personProperty; //2. this gives undefined this.getPersonProperty=function(){ return this.personProperty; //3. this give method not found on object Person var getPersonProperty=function(){ return personProperty; } } var o= new Person(); alert(o.getPersonProperty()); In 1 and 2, this points to current object execution context which is o, so both should produce same result, but in 2 I think this.personProperty points to some other execution context. In 3 as there is no "this" reference however "var" should put this in the "o" object instance and it should still work right ? but they don't, what is happening here?
  11. One more thing, I was reading Wrox professional Javascript book. It states that there are six DataTypes undefined,null,String,Number,Boolean primitives and Object which is complex. But when did var f= function() {} typeof(f). It gives "function". That means we have function dataType also right? In that case is the book wrong, it is 3rd edition. How many datatypes are really there then ?
  12. Hi, var str="something" typeof(str) -----> "String" var strObject = new String() typeof(strObject) -----> Object I was expecting typeof(strObject) to return String, Yes it is a object, but, of type String. Does that mean "String" dataType is primitive and not a object
×
×
  • Create New...