Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
Quick question about javascript
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="RastaLulz" data-source="post: 439712" data-attributes="member: 1"><p>As [USER=9520]@Wess[/USER] mentioned, ES6 has <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes" target="_blank">classes</a>, although to get cross browser support you'll want to use <a href="https://babeljs.io/" target="_blank">Babel</a> for the foreseeable future (assuming you're building something for the browser, and not something you'd run server side).</p><p></p><p>If you wanted to make your pseudo-class slightly more like an actual class you could do the following:</p><p>[CODE]</p><p>/**</p><p> * @constructor</p><p> * @name Person</p><p> */</p><p>var Person = function(name, age) {</p><p> this.name = name;</p><p> this.age = age || 0;</p><p>};</p><p></p><p>Person.prototype = {</p><p> /**</p><p> * @function</p><p> * @name Person#getName</p><p> */</p><p> getName: function () {</p><p> return this.name;</p><p> },</p><p></p><p> /**</p><p> * @function</p><p> * @name Person#setName</p><p> */</p><p> setName: function (name) {</p><p> this.name = name;</p><p> },</p><p>};</p><p>[/CODE]</p></blockquote><p></p>
[QUOTE="RastaLulz, post: 439712, member: 1"] As [USER=9520]@Wess[/USER] mentioned, ES6 has [URL='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes']classes[/URL], although to get cross browser support you'll want to use [URL='https://babeljs.io/']Babel[/URL] for the foreseeable future (assuming you're building something for the browser, and not something you'd run server side). If you wanted to make your pseudo-class slightly more like an actual class you could do the following: [CODE] /** * @constructor * @name Person */ var Person = function(name, age) { this.name = name; this.age = age || 0; }; Person.prototype = { /** * @function * @name Person#getName */ getName: function () { return this.name; }, /** * @function * @name Person#setName */ setName: function (name) { this.name = name; }, }; [/CODE] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
Quick question about javascript
Top