Object's value and prototype issue

Joymmes

New Member
I'm trying to create a new class, but it doesn't seem to be working. Here's the code:\[code\]<script>var myClass = function(arg){ return new init(arg);}var init = function(arg){ return arg;}init.prototype.prop = true;</script>\[/code\]The problem is that \[code\]myClass('foo')\[/code\] doesn't return \[code\]'foo'\[/code\] as expected. Instead, it returns \[code\]init\[/code\].Then I tried this code:\[code\]var init = function(arg){ return [arg];//Now init returns an array}\[/code\]The \[code\]myClass('foo')\[/code\] returns \[code\]['foo']\[/code\], but then \[code\]myClass('foo').prop\[/code\] turns into \[code\]undefined\[/code\]. Does anyone know how to solve it?EDIT: I want to create this class more or less as jQuery does.For example: \[code\]$('div')\[/code\] returns directly a value (in case, all div tags), but not an object with a property that stores this values
 
Top