So, today I learned how to define classes, create instances of Objects, and use inheritance. I thought I was all set to go and was excited about finally getting something accomplished today (other than just learning stuff).
Well I didn't get far.
I'm stuck on Namespaces in JavaScript.
The following does not work:
From what I understand, the Type.registerNa mespace method to creates a namespace where I can place my classes required in my project.
If I remove the Namespace, it works fine:
Could someone please explain what is going on here?
Is the Type class part of the Ajax Framework that ASP.NET uses? Or is it a native JavaScript Object?
Thanks again,
-Frinny
Well I didn't get far.
I'm stuck on Namespaces in JavaScript.
The following does not work:
Code:
<html>
<body>
<script type="text/javascript">
Type.registerNamespace("MyNamespace");
MyNamespace.Foo = function(firstNumber,secondNumber){
this.a = firstNumber; //"a" is now a property of the Foo Object
this.b = secondNumber;//"b" is now a property of the Foo Object
};
MyNamespace.Foo.prototype = {
Add: function(){return this.a + this.b;},
Divide: function(){return this.a/this.b;},
Multiply: function(){return this.a * this.b;}
};
MyNamespace.Foo.registerClass('MyNamespace.Foo');
var MyNamespace.instanceOfFoo = new Foo(2,3);
document.write(instanceOfFoo.Multiply());
document.write("<br />");
</script>
</body>
</html>
If I remove the Namespace, it works fine:
Code:
<html>
<body>
<script type="text/javascript">
Foo = function(firstNumber,secondNumber){
this.a = firstNumber; //"a" is now a property of the Foo Object
this.b = secondNumber;//"b" is now a property of the Foo Object
};
Foo.prototype = {
Add: function(){return this.a + this.b;},
Divide: function(){return this.a/this.b;},
Multiply: function(){return this.a * this.b;}
};
var instanceOfFoo = new Foo(2,3);
document.write(instanceOfFoo.Multiply());
document.write("<br />");
</script>
</body>
</html>
Is the Type class part of the Ajax Framework that ASP.NET uses? Or is it a native JavaScript Object?
Thanks again,
-Frinny
Comment