本文介绍了JavaScript对象和原型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaScript对我来说是一个非常奇怪的地方...


所以,我决定,在我尝试创建一个Object之前,我应该首先了解Objects。我之前在教程的帮助下创建了一个。该教程很复杂,因为向我展示了如何创建一个JavaScript对象,它是一个表示我的.NET对象,以及如何使两者一起工作......显然教程不是很清楚什么是在JavaScript对象中...甚至我对JavaScript对象的广泛评论我仍然没有真的知道发生了什么...当时我对.NET概念比对教程中使用的JavaScript技术更感兴趣。


无论如何,我从基础开始:我如何创建一个JavaScript对象。

令我惊讶的是所有函数都是对象,所有对象都是函数,我对这种新思维方式并不满意,因为它真的很奇怪......但是事情就是这样。


我接下来要做的就是弄清楚我在教程中创建JavaScript对象的工作。此Object使用prototype属性(显然是一个Object并且是所有函数的属性)来向Object添加函数和属性。


所以我开始玩弄我自己的一个愚蠢的小(简单)对象......


请参阅下面的评论代码我对此感到困惑

JavaScript is a very strange place for me...

So, I decided that, before I attempt to create an Object, I should first learn about Objects. I had actually created one before with the help of a tutorial. The tutorial was complicated because showed me how to create a JavaScript Object that is a representation my .NET Object and how to get the two to "work together as one".... apparently the tutorial was not very clear about what was going on in the JavaScript Object...and even with my extensive commenting of the JavaScript Object I still didn''t "really" know what was going on...at the time I was more interested in the .NET concepts than the JavaScript techniques being used in the tutorial.

Anyways, I started with the basics: how do I create a JavaScript Object.
To my surprise all functions were Objects, all Objects were Functions and I was not pleased with this new way of thinking because it''s really strange...but it''s just how things are.

The next thing I did was try to figure out what I had done to create the JavaScript Object in the tutorial. This Object uses the prototype property (which is apparently an Object and is a property of all functions) to add functions and properties to the Object.

So I started playing around with a silly little (uncomplicated) Object of my own...

Please see the comments in the following code for what I''m confused about:

展开 | 选择 | Wrap | 行号

推荐答案

展开 | 选择 | Wrap | 行号




这篇关于JavaScript对象和原型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 04:48