Comments (4)
Seems that it does not work when using Object.create() new javascript implementation.
It works when creating objects in this way:
function myobject() {
this.container = new CAAT.Actor();
};
Any ideas?
from caat.
This has nothing to do with CAAT, but with javascripts prototypal inheritance.
I'll try an attempt to explain this:
First look at this jsbin (your example-code)
Why do obj1.container and obj2.container all of a sudden have the same id?
When objects are created with Object.create, the original object is added as the prototype to the new object. Since all objects and array are passed by reference in javascript, that means that the actor in original object (testing) and the actor of the copy (for example obj1) are actually pointing to the same instance of CAAT.Actor
When you create an actor using the new keyword, a new object ("this") is created, and the properties that are added in the CAAT.Actor constructor are added. Finally the new "this" object is returned.
What does this mean in practical use?
I think i will confuse you even more now, but this works perfectly fine – Why?
Because when i call setId on for example obj1, what happens behind the scenes is
this.id = "obj1" //"this" refers to obj1
in your example, what happened was
this.id = "obj1" //"this" refers to obj1.prototype, which is shared by all three
Anyway i hope this cleared things out a little, I also recommend the Inheritance chapter in "Pro Javascript Design Patterns" by Dustin Diaz and Ross Harmes if you'd like to know more about this!
from caat.
Thanks for your help.
Maybe it's not a good idea to use this pattern.
I will take a look at that book
from caat.
Non CAAT related questions must be asked in the forums at http://groups.google.com/group/caatjs?hl=es
Thanks for answering Karl.
Thanks.
from caat.
Related Issues (20)
- audio loop issue in firefox
- Exact pixel hit detection HOT 2
- Rendering wrong when use director.enableResizeEvents(CAAT.Director.RESIZE_PROPORTIONAL) HOT 2
- Actor SetAsButton Touch not working on CocoonJS 1.3 ? HOT 3
- Actors with SpriteImage can't rotate or scale correctly with anchors HOT 6
- Is CAAT running well in mobile
- Wrong license creation produced invalid js files within build folder. HOT 1
- Bug in actor.js /setRotationAnchor()
- Inconsistencies when hiding actor after a end of a behavior
- Cannot Remove Directors
- CSS renderer seems to be broken
- Small bug in __mouseDownHandler in Director.js
- Stop sprite image animation HOT 4
- collision image HOT 5
- uncaught exception: adding to a container an element with parent. HOT 3
- Demo not working HOT 1
- disable ctrl rotation in actor with enableDrag true
- How to add a method on complete event of RotateBehavior HOT 2
- Need to allow user to enter his name for score submission
- Path management example starting point
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from caat.