JavaScript Rhino book essay (ii)

Source: Internet
Author: User
Tags access properties error handling

Tag: The return traversal operator must nbsp The takeaway ALS Sub.

Sunny, small tenon sitting in front of the computer, next to put a cup of tea

Good one afternoon, knocking on the code, life ah.

Suddenly, the sound of a key broke the calm, is the mother woke up to say back.

"Did you eat it?"

Not

"Call it a takeaway."

Oh

Small Tenon ordered the takeaway, went on to the computer next. Then wake up and turn on the stereo and take a bath.

"Mom, I'm learning, your voice is small."

"This is my house."

Little Tenon Heart sank

The takeout is coming, the shower is finished.

The little Tenon opened the lunchbox and ate

Thinking about waking up every night and dad's TV movie subwoofer no discussion small tenon very disappointed

After eating the little tenon put down a sentence

"You never cared about my study."

Ran out with the bag.

Outside the wind more scraping, small tenon walking on the road, the eyes are somewhat moist. Unconsciously came to the school's huge playground, the sky is a bit dark, she seems to see a black shadow from the steps over there floated, and disappeared.

The little Tenon sat under the basketball stand, leaning against the pillars, sleepy

Trance She seems to come to a huge candied fruit below, each color is different, very good-looking, she smelled, the bottom of the nut is walnut, she followed this chain to climb up, this is the strawberry core, this is the apple core ... To the top, I saw Mr. JS is on the top of the bamboo sticks, holding a null in his hand.

R Wipe Your eyes: Is this what you do?

J Mysterious: Candied fruit can not give the crying child to eat, ah no, you are so big, it should be a crying woman to eat.

R dawned: I know, this is the book of the prototype chain! The original long like this, haha.

J: Please, give your father a little dignity, okay, it's daoxing.

R: Just now I was just from a subclass to the parent class to do the query, the real inheritance is embodied in this "check" operation

J: Yes, that's true, but it's important to modify the properties, and guess what I'd think about o.x=1?

R: Well first of all to see if there is this x attribute, like I just looked at, if not, then create a, this is the characteristics of JS

J Bad laugh: What if there is?

R: There, there is Bai, the assignment is successful!. Oh, no, no, no, it's like there's a situation where a read-only attribute is probably a failed assignment.

J: Well, it's just.

R:?

M: All right, young man, let me tell you something. There is actually an attribute that exists, and this property is a property of the setter method, then the subclass object:

R: The setter method will be called!

J: Well, you, we're going to look at this in depth later.

R (a bit unhappy): What happened to me today, you know?

J: Haha, I'm the dream in your belly, how can you not know? Everyone makes mistakes, not to mention the things in the family, who are wrong about who is right. Don't think about it, there's no ending.

R: haha who makes no mistakes.

(Suddenly remembered what): Then I will give you a question, if the Access property error, what should I do?

J: What do you mean by an Access attribute error?

R: Well, for example, I book.subtitle to access a property, but actually the book does not have this property, what to do

J: This can't be wrong, I'll return a undefined

R: What if I continue to question access to book.subtitle.length?

J: That's the equivalent of accessing the undefined property, which is not going to be an error. You help me to think about, how to prevent such a situation!

R: Better than this var len=book && book.subtitle && book.subtitle.length

J: Yo, it's very advanced, I'm still waiting for you to write

if (book) {

if (book.subtitle) {

Len=book.subtitle.length

}}, and then make a mockery of it naturally:)

R: Shocking, young people now, know a && is difficult (666), here I borrowed its short-circuit behavior

J (Witty and proud): Gee, that's awesome. I want to delete a property.

R (think about a bit no results, hurriedly secretly Baidu): Ah delete is not the deletion of the keyword it is so delete Book.author is good pull

J: Hey, are you out of here, my son? Let's make a guessing game ~

R: Ah, it sounds boring, all right, let's get the horses.

J: Do you think I will not let you "delete the end" When I design the language?

Like what

a={

P:{x:1}

}, assuming there is B=A.P, now i delete A.P, ask me to go back to visit b.x still have a chance?

R: Well, that's what you're asking. It seems that you can still get the value (this is really a time to test the emotional quotient), the above chestnut is a little less rigorous AH

J: Oh? Do you dare dis the teacher? Keep talking!

R: It will cause memory leaks, no way, in the future to destroy the object when you want to traverse the properties of the property, delete the

J (a little satisfied): Hmm. All right. Then I ask you again, if it is you, how to handle the deletion of inheritance properties?

R: Uh.. (Is it me?) Next Life Bar elder brother) just now is "segmented" deletion, this time certainly not good to where

J (Children still count): Well, it's not exactly the same as the bar.

R:?

J (time to show a wave of jargon) The delete operator can only be deleted from its own property and cannot be removed from the inherited property.

R: And I said a meaning

J: To delete an inherited property, you must remove it from the prototype object that defines it (with emphasis) and this affects all objects that inherit from this prototype

R: Oh, that's the last ray.

R (born provocative): But think about it, how does the delete have to have a return value, True or false?

J: It seems you've seen that I'm going to let it return a Boolean value.

R: Well, I've got it all figured out for you. For example o={x:1}; If delete o.x, then it will be successful, then return True, if the program ape after the delete o.x again is not wrong, when it is not done, continue to return true. The last thing is, (think of the inheritance just learned), because o this way of creating objects will inherit the object property toString, so, hehe, according to the above rules, you try to delete o.tostring, Actually do nothing (just discussed the problem of not deleting inherited attributes), so all three of these cases return true.

J: Well, logic seems clear.

R: Looks like?

J: Do you have the ability to analyze the situation of false?

R:... Well, I guess the delete object.prototype is inappropriate because. Its prototype property is configurable to False

J: Well, the principle is right. Some built-in objects have properties that are configurable as false, such as the properties of global objects created by variable declarations and function declarations

R: Ah that's not var x=1 and function f () {}, which means I delete this.x, delete this.f will be like Deleteobject.prototype, return false?

J: Well, it's dripping.

R (a restless heart urges it again to dis Mr. JS): Oh, but. I see This.x=1; Delete x returns True, huh?

J: Well, yes, because the front this.x is creating a configurable global property, and it doesn't use Var.

R (Too young too naive?) No no no continue dis): OK, that was the last time the next door Xiao Wang wrote, why did you report a grammatical error?

J: (Strong and strong Old Ginger head): Oh that is in strict mode, this time can not be shortened, must write delete this.x pull.

R (to be convinced): Speaking so much, I should go home.

J: Young people should read more (don't dis me all the while)

R: Goodbye (dis you are not because like you?)

Next: (Earthy sweet words perfect end, small tenon back home, full of access properties, error handling, delete attributes, and think of today's candied fruit, happy to fall asleep)

JavaScript Rhino book essay (ii)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.