vendredi 18 mars 2016

reopenClass method can not pass attribute named name of it?

I am learning to use reopenClass method when I was introduced to a property called name, but when I run the code when an error occurs, the following error message, but I changed the name of another property, but no problem. I find this method of API, we did not see the instructions. I guess the name is not the method reopenClass reserved keywords?

Error message

ember.debug.js:18772 Uncaught TypeError: Cannot assign to read only property 'name' of function 'function () {
if (!wasApplied) {
  Class.proto(); // prepare prototype...
}

if (argume...<omitted>... }'

This is my code

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Ember.js • Guides</title> 
  <script src="http://ift.tt/1RSyOuK"></script>
   <script src="http://ift.tt/2586xdC"></script>
    <script src="http://ift.tt/1RSyR9W"></script>
        
        <script type="text/javascript">

        MyObject = Ember.Object.extend({
          name: 'an object'
        });

        MyObject.reopenClass({
            canBuild: false,
                username: 'blog.ddlisting.com' 
                //Here a bit strange, do not know why you can not use the name for the 
                // custom property name will prompt this property is self-reading, 
                //using username no problem! !
                ,name: 'test'  
        });

        //  Gets static property values
        console.log(MyObject.canBuild); // false
        //  For general property values
        console.log(MyObject.create().get('name'));  // an object

        </script>
  </head>
   
   
  <body>
  
  </body>
</html>

reopenClass method API

I hope you read the description, look forward to your reply. thanks !!

Aucun commentaire:

Enregistrer un commentaire