1
0
Fork 0
Commit Graph

525 Commits (master)

Author SHA1 Message Date
Mike Gerwitz 649356ef23 Refactored interface module invocation into separate functions for named and anonymous 2011-03-04 23:35:28 -05:00
Mike Gerwitz e3075b0479 Refactored class module invocation method into separate functions
- The class module is getting too big. Something will have to be done soon.
2011-03-04 19:49:15 -05:00
Mike Gerwitz b158e542d5 Declaring named class will throw error for extreaneous arguments 2011-03-04 16:36:15 -05:00
Mike Gerwitz dca7653adf Merge branch 'master' into visibility/master 2011-03-04 00:26:02 -05:00
Mike Gerwitz 7bb87e370f No need to recheck the type each time 2011-03-04 00:24:42 -05:00
Mike Gerwitz 009c4a93e9 Interfaces now have sane/useful values when converted to strings 2011-03-04 00:19:02 -05:00
Mike Gerwitz ec7b4e2b6b Updated class module docblock 2011-03-04 00:17:25 -05:00
Mike Gerwitz 85e687e29c Added Interface.isInterface() 2011-03-03 23:59:37 -05:00
Mike Gerwitz 4148f8742d Merge branch 'master' into visibility/master
Conflicts:
	test/test-class-extend.js
2011-03-03 23:29:20 -05:00
Mike Gerwitz 81d03cb984 Altered class toString() representations to be more consistent with JS 2011-03-03 23:00:59 -05:00
Mike Gerwitz e2cba458d8 Class instances now have different default toString() implementations than uninstantiated classes
- Instance id is not yet included, as that is currently in a different branch
2011-03-03 22:53:20 -05:00
Mike Gerwitz 840a495017 Began implementing named classes
- toString() implementation
2011-03-03 22:33:18 -05:00
Mike Gerwitz d23ae6210c Initial implementation of natural class definition by invoking class module 2011-03-03 19:43:20 -05:00
Mike Gerwitz 3f915d3644 The interface module may now be invoked, providing a more natural looking means of declaring interfaces 2011-03-03 19:08:24 -05:00
Mike Gerwitz bc9e2bb7b2 Fix setting public properties
- This currently only works with ES5 engines
  - Fallback to follow so this will work with pre-ES5 engines
- As such, I do not recommend using this commit outside of ES5-compliant engines that work properly with getters/setters
  - This does NOT include IE8, as IE8 only works with getters/setters on DOM elements
2011-03-02 23:21:10 -05:00
Mike Gerwitz 74c2fc57c1 Initial implementation of protected members
- This was quite the pain in the ass
- There are additional considerations. I DO NOT recommend using this commit. Check out a later commit.
2011-03-02 20:43:24 -05:00
Mike Gerwitz 2af7bcf45d Merge branch 'master' into visibility/master 2011-03-02 07:54:52 -05:00
Mike Gerwitz e239352fc0 Resolved bug that was causing the system to think that Object prototype members were part of the abstract member list when attempting to define a method with the same name 2011-03-01 12:11:36 -05:00
Mike Gerwitz e3561a492f Modified interface property message to be a bit more helpful in a likely common scenerio 2011-03-01 09:17:24 -05:00
Mike Gerwitz 38c16048cb Began adding protected/private member support
- No longer adding ANY properties to prototype
- protected/private members no longer part of the public access level
2011-01-27 22:35:40 -05:00
Mike Gerwitz 8c7ad787c8 Abstract methods list is no longer public 2011-01-25 00:24:50 -05:00
Mike Gerwitz fb5d541ea3 Removed old console.log 2011-01-25 00:23:56 -05:00
Mike Gerwitz fa8cddea07 Meta now uses deep cloning 2011-01-25 00:19:48 -05:00
Mike Gerwitz 881edc0cc6 Preparing to remove abstractMethods from public prototype; now uses hash for performance since it no longer needs to be referenced cleanly externally
- It will be later referenced via reflection
2011-01-25 00:13:47 -05:00
Mike Gerwitz 194aa02402 {new,} TypeError 2011-01-24 23:57:19 -05:00
Mike Gerwitz 188ad2f4eb Getters/setters are not supported within interface definitions 2011-01-24 23:56:54 -05:00
Mike Gerwitz c7b262b271 Concrete methods cannot be overridden by abstract methods 2011-01-24 23:52:06 -05:00
Mike Gerwitz 37e5b1d94d util.propCopy() no longer needed 2011-01-24 23:38:27 -05:00
Mike Gerwitz 70f5d09c34 Interface now uses propParse and member builders 2011-01-24 23:35:45 -05:00
Mike Gerwitz cd7b2563e5 Combined shared conditions in separate if statements 2011-01-24 23:30:32 -05:00
Mike Gerwitz eba32ed4cb Beginning to move Class over to use member builders 2011-01-24 23:28:48 -05:00
Mike Gerwitz 2a54662716 Added getter/setter keywords to propParse 2011-01-24 23:27:55 -05:00
Mike Gerwitz 5a3b401647 Began moving abstract logic out of propCopy 2011-01-24 20:58:58 -05:00
Mike Gerwitz 96d2f74dae Method builder wraps overrides in an override function 2011-01-21 23:16:20 -05:00
Mike Gerwitz e03d5861bb Overridden methods must have >= length parameter lists 2011-01-21 22:19:22 -05:00
Mike Gerwitz b8a6aa2af6 Method builder does not permit overriding properties with methods 2011-01-21 21:53:31 -05:00
Mike Gerwitz 12e5b48a7d Cannot override method with property 2011-01-21 21:43:18 -05:00
Mike Gerwitz dea6972416 Began adding basic method builder (currently operates the same as property builder)
- They are essentially the same, but the method builder will have additional logic (e.g. method overriding) and support different keywords
2011-01-21 20:54:55 -05:00
Mike Gerwitz 94d6fb1655 Added params to member_builder.initMembers() docblock 2011-01-21 00:09:26 -05:00
Mike Gerwitz f55def4f06 Preparing class to use member_builder 2011-01-21 00:03:41 -05:00
Mike Gerwitz 2205af8c07 Can initialize member object with existing objects for each level of visibility 2011-01-20 23:56:39 -05:00
Mike Gerwitz 96cee9660b Began adding member_builder.initMembers() 2011-01-20 23:53:00 -05:00
Mike Gerwitz 3c45912f25 Added getter/setter to member builder 2011-01-20 23:50:53 -05:00
Mike Gerwitz a58b7989ee Throws TypeError if multiple visibility keywords are given to member builder 2011-01-20 22:11:36 -05:00
Mike Gerwitz 9d9d00388c Presumably private keywords will be used more frequently than protected, if the class is properly encapsulated 2011-01-20 21:51:35 -05:00
Mike Gerwitz 7f92a76e1f Member builder uses public prototype by default 2011-01-20 21:50:52 -05:00
Mike Gerwitz f27b0b01ab Member builder recognizes private members 2011-01-20 21:48:09 -05:00
Mike Gerwitz 0ba3122db5 Member builder recognizes protected members 2011-01-20 21:46:49 -05:00
Mike Gerwitz 23a7d9d540 Began adding member_builder 2011-01-18 23:47:58 -05:00
Mike Gerwitz 96f5b8ff58 Multiple spaces now properly handled in keyword parser 2011-01-18 19:33:33 -05:00
Mike Gerwitz 7dab5c7b20 Keywords are now returned by propParse 2011-01-17 22:24:02 -05:00
Mike Gerwitz afc5d4668d Abstract classes also have a more intuitive string representation 2011-01-17 20:22:30 -05:00
Mike Gerwitz d19638be4f Classes now return a more intuitive string representation 2011-01-17 20:20:39 -05:00
Mike Gerwitz 7fb0f6a820 Classes now contain implement() method 2011-01-10 19:56:09 -05:00
Mike Gerwitz ec9f24a926 Moved implement() into its own method, accepting destination object as the first parameter 2011-01-10 19:00:26 -05:00
Mike Gerwitz fba94f2e0b Added todo to profile propParse's use of fvoid vs if statements 2011-01-09 19:44:09 -05:00
Mike Gerwitz 7301ddbac2 [minor] formatting fix 2011-01-09 19:41:47 -05:00
Mike Gerwitz aa1d38b007 Added deep cloning for objects 2011-01-09 01:46:46 -05:00
Mike Gerwitz 0f905481bf Added deep cloning for arrays 2011-01-09 01:38:40 -05:00
Mike Gerwitz 3e8dba2fdc Added missing comma to variable list 2011-01-09 00:40:35 -05:00
Mike Gerwitz 56c13b757b isInstanceOf() now works with interfaces 2011-01-04 00:37:54 -05:00
Mike Gerwitz c3b00ab9b7 Encapsulating implemented list (can use isInstanceOf() or a future reflection API) 2011-01-03 23:41:45 -05:00
Mike Gerwitz 0b112dac51 Abstract method list is now updated for classes that implement interfaces 2011-01-03 23:25:27 -05:00
Mike Gerwitz c12ac412cb Class.{implements => implement} - like Class.extend(), we're looking for a verb 2010-12-30 09:54:53 -05:00
Mike Gerwitz d5d6082bfb Interface methods are now copied to the class prototype (basic implementation - no deep copy for interface subtypes yet) 2010-12-29 23:34:12 -05:00
Mike Gerwitz 459d5e967b Classes now store implemented interfaces in a list (does not yet import methods) 2010-12-29 23:33:30 -05:00
Mike Gerwitz 9ef73195c5 [minor] formatting fix 2010-12-29 22:51:29 -05:00
Mike Gerwitz ca71fc6296 Remove accidental attach of isInstanceOf() to Class 2010-12-29 22:45:47 -05:00
Mike Gerwitz 80b0732be1 Interfaces cannot be instantiated 2010-12-29 22:40:23 -05:00
Mike Gerwitz 76969201fb Added isA() as an alias for isInstanceOf() 2010-12-29 21:37:11 -05:00
Mike Gerwitz 6a24f2ad13 Added isInstanceOf() partially applied function to class instances 2010-12-29 21:32:16 -05:00
Mike Gerwitz 96909732db Began adding isInstanceOf, starting with prototype chain checks 2010-12-29 21:13:21 -05:00
Mike Gerwitz 0103df3e71 Fixed self-invoking constructor issue in IE 2010-12-29 09:43:00 -05:00
Mike Gerwitz 38a6a4ee6a Added missing semi-colons that would otherwise be inserted via semicolon insertion 2010-12-28 22:10:12 -05:00
Mike Gerwitz 789f2390af All functions are now camelCase 2010-12-28 22:08:30 -05:00
Mike Gerwitz 004ccfa05b Interfaces cannot inherit from Classes 2010-12-28 21:56:55 -05:00
Mike Gerwitz c9d0e027fa Added isClass() and isClassInstance() methods 2010-12-28 20:58:42 -05:00
Mike Gerwitz 928a0ea297 Removed Interface.abstractMethod() in favor of 'abstract' keyword 2010-12-28 20:13:50 -05:00
Mike Gerwitz 44186068b4 Class constructors are now self-invoking
- Permits omitting 'new' keyword, which is a style preferred by some (such as Crockford)
- It's very difficult to use apply() with the 'new' keyword - this method permits a simple way of passing an argument list to the constructor
2010-12-28 19:05:53 -05:00
Mike Gerwitz 828a366f29 Renamed prop_parse.{parse => parseKeywords} 2010-12-27 23:12:37 -05:00
Mike Gerwitz 87e293e33f Property keyword parser now simply checks for spaces (to be flexible enough to support any keywords in the future) 2010-12-27 23:04:50 -05:00
Mike Gerwitz 3277a30d54 Removed now unnecessary abstract keyword check from util.propParse() 2010-12-27 22:32:30 -05:00
Mike Gerwitz 1364d5967f Abstract methods must contain a parameter list as an array 2010-12-27 22:30:28 -05:00
Mike Gerwitz 69391f9b48 Finished correcting assertion tests with new implementation 2010-12-27 22:20:29 -05:00
Mike Gerwitz e789e58000 Removed Class.abstractMethod in favor of property keyword 2010-12-27 22:11:37 -05:00
Mike Gerwitz f705f38640 Began adding prop_parser module and moved existing property keyword parser function into it 2010-12-27 20:56:36 -05:00
Mike Gerwitz 9666a5f80f Began adding property keyword parsing (concept) 2010-12-27 20:49:59 -05:00
Mike Gerwitz 3ef2a28e24 Merge branch 'master' of github.com:mikegerwitz/easejs 2010-12-23 15:59:57 -05:00
Mike Gerwitz f58586fc94 Added tests to ensure constructor is properly applied to subtypes 2010-12-23 15:57:45 -05:00
Mike Gerwitz a93ff61bde If setting a secure property fails, it will force a fallback to prevent performance degredation due to exceptions 2010-12-22 22:17:07 -05:00
Mike Gerwitz 7e7080ccbf util.defineSecureProp() no longer performs fallback check on each invocation 2010-12-21 22:41:50 -05:00
Mike Gerwitz d5f37f294e IE8 does not support Object.defineProperty on non-DOM objects
(see http://stackoverflow.com/questions/3830800/object-defineproperty-in-es5)
2010-12-21 14:37:34 -05:00
Mike Gerwitz e1d7b80d46 Calling hasOwnProperty via Object prototype in case it has been overridden 2010-12-21 10:09:18 -05:00
Mike Gerwitz 3a0972c79d Removed unneeded 'continue' statement 2010-12-20 13:51:44 -05:00
Mike Gerwitz 1f40665e57 Added tests for util.defineSecureProp() 2010-12-20 13:43:12 -05:00
Mike Gerwitz 0d84cd829a util.defineSecureProp was failing in browsers that do not support Object.defineProperty()
- This is untested! Test needed.
2010-12-20 10:04:11 -05:00
Mike Gerwitz cd9ef1ea71 Finished refactoring to remove result_data object in class extend() function 2010-12-19 13:54:31 -05:00
Mike Gerwitz 1ff9408885 Rearranged util.overrideMethod() arguments to match methodOverride propCopy() action (to avoid unnecessary mistakes and confusion) 2010-12-19 00:12:41 -05:00
Mike Gerwitz 600e389b40 Refactored abstract method logic out of util.propCopy() into class extend() 2010-12-19 00:11:39 -05:00
Mike Gerwitz 2789e5fcf9 Abstract map no longer passed to method_override() - it's only used in that method 2010-12-18 10:57:00 -05:00
Mike Gerwitz e39cfea741 Now exporting util's array_shrink() as util.arrayShrink() 2010-12-18 09:38:58 -05:00
Mike Gerwitz 3a2ddbb29b class.js 'extending' var is an argument and shouldn't be declared with var keyword 2010-12-18 08:24:15 -05:00
Mike Gerwitz 2c49e9719f util.propParse() now ignores instance prototype properties 2010-12-18 07:07:27 -05:00
Mike Gerwitz f2baf82100 Removed unneeded var 2010-12-18 06:59:35 -05:00
Mike Gerwitz 755b79725f Corrected attach_prop_init() documentation (__propInit => __initProps) 2010-12-16 23:56:35 -05:00
Mike Gerwitz a06d9a7204 Ensured __initProps() is treated as a reserved method and cannot be declared within Classes 2010-12-16 23:55:56 -05:00
Mike Gerwitz a60fe9c2de Class extend() now implements propCopy's performDefault (see previous commit) 2010-12-16 23:51:22 -05:00
Mike Gerwitz 6b6ffe0134 propCopy() parser function overrides can now invoke default functionality 2010-12-16 23:49:52 -05:00
Mike Gerwitz 591434b82f [*] Previous commit (property cloning per instance) now applied to subtypes as well 2010-12-16 23:37:18 -05:00
Mike Gerwitz fe853b505b [*] Properties are no longer shared between class instances
- Properties were previously shared on the prototype level, acting as though they were static class properties, which can cause some nasty bugs
2010-12-16 23:18:30 -05:00
Mike Gerwitz 6efaba7fc5 Added util.clone(); does not yet support deep cloning 2010-12-16 23:15:42 -05:00
Mike Gerwitz a2c894b6bb Added ability to override propCopy() parser functions 2010-12-16 21:11:07 -05:00
Mike Gerwitz 5126c71a2d Using TypeError instead of Error for property type inconsistiencies 2010-12-10 00:00:47 -05:00
Mike Gerwitz 25dc7e031e Ensured properties cannot be overridden with methods 2010-12-07 20:24:51 -05:00
Mike Gerwitz 459335cf62 attempt_override() within propCopy() no longer needed after previous commit 2010-12-07 00:49:00 -05:00
Mike Gerwitz eced0a7e91 Both concrete and abstract methods now use the same callback in propParse()
- Now uses an is_abstract parameter
- Intended to reduce clutter and duplicate code
2010-12-07 00:46:50 -05:00
Mike Gerwitz 52b1ef657f Resolved failing test (methods may only be overridden with methods) with propParse() 'each' 2010-12-07 00:41:30 -05:00
Mike Gerwitz 994b8e16fa [1 failing test] Added support for 'each' in propParse() 2010-12-07 00:39:25 -05:00
Mike Gerwitz abefb0858b [1 failing test] Crude beginning of implementation of propParse()
- Looks ugly now because it is. Attempting to refactor before doing a proper implementation. Baby steps.
2010-12-07 00:38:51 -05:00
Mike Gerwitz fd2b3ccc6d Added support for getters/setters in propParse() 2010-12-05 20:50:13 -05:00
Mike Gerwitz 20b78ba73a Minor formatting change in propParse test 2010-12-04 14:05:56 -05:00
Mike Gerwitz 6fd31a8e76 Added abstract method support to propParse() 2010-12-04 14:03:26 -05:00
Mike Gerwitz 4037cc1343 Began adding util.propParse() to simplify design (supports scalar, arr and obj props and concrete methods) 2010-12-04 13:59:06 -05:00
Mike Gerwitz 729b977088 Fix of unintended global var 2010-12-03 07:19:16 -05:00
Mike Gerwitz 60025bd048 Added extend method to Interface 2010-12-01 23:27:31 -05:00
Mike Gerwitz 78e1913eb9 Comment spelling correction 2010-12-01 23:19:59 -05:00
Mike Gerwitz 0d45716a43 Added missing space to error string 2010-12-01 23:04:22 -05:00
Mike Gerwitz 84dcca35d2 Interface prototype contains defined methods 2010-12-01 23:01:20 -05:00
Mike Gerwitz c910dafb76 Interfaces permit only abstract methods 2010-12-01 21:39:41 -05:00
Mike Gerwitz 2e930482d2 Abstract methods of subtypes overriding abstract methods must be compatiable with the previous definition 2010-12-01 21:34:57 -05:00
Mike Gerwitz 2e8097e21e Altered abstract method declaration (using strings to represent arguments rather than a function) 2010-12-01 21:13:51 -05:00
Mike Gerwitz 837422c46f Added util.isAbstractMethod 2010-12-01 21:00:15 -05:00
Mike Gerwitz 54432c78fa abstractMethod() moved to util.defineAbstractMethod 2010-12-01 20:45:27 -05:00
Mike Gerwitz b3c4b757e7 util.canFreeze removed, replaced with util.freeze() 2010-12-01 20:41:54 -05:00
Mike Gerwitz c29bd010b0 define_secure_prop moved to util.defineSecureProp 2010-12-01 20:38:50 -05:00
Mike Gerwitz 2edcb8a75e Only methods are permitted within interface declarations 2010-12-01 19:38:30 -05:00
Mike Gerwitz b294f84481 Began Interface development 2010-12-01 19:27:40 -05:00
Mike Gerwitz 1e2e73c9f0 Began moving utility methods into their own module 2010-11-15 23:44:15 -05:00
Mike Gerwitz 0e232b4a2c Freezing class object after creation 2010-11-15 23:22:24 -05:00
Mike Gerwitz f632b93d64 Refactored constructor creation logic for new classes into its own method and placed both functions (and their shared var) into a closure to remove the 'extending' var from the module's scope 2010-11-15 07:07:49 -05:00
Mike Gerwitz 095683ba42 Simply moved extend() function higher up in the source file, since it will be one of the most commonly referenced functions 2010-11-15 06:54:37 -05:00
Mike Gerwitz f9d7dca4b3 Removed old code from attach_extend() 2010-11-14 22:07:04 -05:00
Mike Gerwitz e26d7971ce Refactored abstract method logic 2010-11-14 22:03:55 -05:00
Mike Gerwitz 52944c4207 Grammar 2010-11-14 21:52:02 -05:00
Mike Gerwitz 3f169d87ea Refactored method override logic into its own function 2010-11-14 21:50:56 -05:00
Mike Gerwitz 1a9cc40c31 Refactored abstract method regeneration logic into a array_shrink() function 2010-11-14 21:39:46 -05:00
Mike Gerwitz d4593725a4 If a definition is provided for an abstract method, the concrete implementation must be compatiable (proper number of arguments) 2010-11-14 21:33:13 -05:00
Mike Gerwitz e0657e1c44 abstractFlag now defined using define_secure_prop() 2010-11-14 21:18:40 -05:00
Mike Gerwitz 0d1ba74415 Ensured abstract classes cannot be instantiated and permitted their instantiation during extending so that it may be used in the subclass's prototype 2010-11-14 20:48:39 -05:00
Mike Gerwitz 746a9ee53d Class.isAbstract() now defined using define_secure_prop 2010-11-14 20:31:23 -05:00
Mike Gerwitz 113e3b974f Properly implemented abstract methods list 2010-11-14 20:30:33 -05:00
Mike Gerwitz ad4b317955 Refactored defineProperty() code into define_secure_prop() function to reduce duplicate code 2010-11-14 01:37:12 -05:00
Mike Gerwitz d5b4477109 Abstract methods are now passed to subtypes 2010-11-14 01:18:49 -05:00
Mike Gerwitz de979d07f0 Added isAbstract() method to class 2010-11-14 01:10:55 -05:00
Mike Gerwitz 716db6d086 prop_copy() will now keep track of abstract methods 2010-11-14 01:02:57 -05:00
Mike Gerwitz e783713ca7 Added a result_data argment to prop_copy() 2010-11-14 00:56:54 -05:00
Mike Gerwitz 9dc025e6b1 Added setup_props function to prepare for adding multiple properties to generated classes 2010-11-14 00:49:52 -05:00
Mike Gerwitz a083313538 Began implementing abstract methods 2010-11-14 00:47:27 -05:00
Mike Gerwitz 16a91b728e Methods can no longer be overridden with non-methods (anything other than a Function) 2010-11-10 23:42:26 -05:00
Mike Gerwitz c34f40db19 Converted vars to conventional function delcarations (no difference; just preference) 2010-11-10 23:35:57 -05:00
Mike Gerwitz 4e38898c93 Added additional documentation to prop_copy() 2010-11-10 23:31:58 -05:00
Mike Gerwitz 60bf9deaf5 Moved class extend() export to the top of the module to make it more noticable in the mess of functions 2010-11-10 23:30:30 -05:00
Mike Gerwitz 86bbef6f77 Added documentation for attach_extend() 2010-11-10 23:29:28 -05:00
Mike Gerwitz 61985eea47 Added checks for ES5 features 2010-11-10 23:28:20 -05:00
Mike Gerwitz 8422bea1d6 Added getter/setter override support 2010-11-10 23:19:46 -05:00
Mike Gerwitz 0c963d1d00 Added access to parent prototype via parent property 2010-11-10 22:54:24 -05:00
Mike Gerwitz 607bbf7f4c Added support for _super method
- Motivation from John Reisg's "Simple Javascript Inheritance": http://ejohn.org/blog/simple-javascript-inheritance/
2010-11-10 22:49:27 -05:00
Mike Gerwitz 26b70bcd93 Changed license to LGPL
My reason for doing so is more practical - for the same reasons that GNU released glib and
other libraries under the LGPL. The reason is that there are so many other alternatives out
there that are released under more permissive licenses. This isn't anything special. Therefore,
to encourage its adoption, I've released it under the LGPL.

All my larger projects/libraries that have few/no alternatives will be released under the
GPL/AGPL.
2010-11-10 22:07:03 -05:00
Mike Gerwitz 909542d19b Added support for extending classes via convenience method and tests for property inheritance 2010-11-10 21:10:31 -05:00
Mike Gerwitz c42598c47b Class.extend() should not be part of the prototype (we're extending the class, not an object instance) 2010-11-10 21:05:52 -05:00
Mike Gerwitz 6a14b86777 Minor documentation changes 2010-11-10 20:45:33 -05:00
Mike Gerwitz 94835d290a Implemented constructor 2010-11-10 19:19:02 -05:00
Mike Gerwitz 1ee270883e Began implementing constructor (not yet operable - test will fail) 2010-11-10 19:02:52 -05:00
Mike Gerwitz 8d6c2645bc Began adding Class.extend() 2010-11-10 18:40:36 -05:00
Mike Gerwitz 979331cda3 Initial commit beginning to outline concept 2010-11-10 17:41:12 -05:00