After doing some calculation, I’m here anyway ^_^
Wuyou~~It’s been a long time….. Post something about the principle,
[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
(stroll's follow-up)
Of course, you can also use the following methods without "plug-in"... However, you need to use Script5.5 to use
For example, call method and apply method... The following is how to use call The method to implement
apply is similar, except that the parameters called later are arrays. For details, you can refer to the MSScript5.6 instructions.
Bencalie, do you still remember when you told me how to use call apply? Is this answer satisfactory this time? If you need to introduce external Js, you need to refresh to execute
]
(stroll's follow-up)
Pay attention to the this.Prototype variable of the so-called "inherited object" (I didn't pay attention at first, thinking it was a keyword... which made me struggle to find information)
this. Prototype = new JSObject(); // Note: This is not a lowercase prototype
this.Prototype.Speak = function(s){.....}
Feedback directly after constructing the object return this .Prototype In fact, this is the JSPObject object.
is not a JSHuman object, so var o = new JSHuman();
//westfly original //Don't ask me what's the use, just remember it when you need it one day functionJSObject() { this._Name = "JSObject"; this.Set_Name = function(Value){ this._Name = Value; } this.Get_Name = function(){ return this._Name; } } function JSHuman() // extends JSObject { this.Prototype = new JSObject(); // Note: this is not a lowercase prototype this.Prototype.Speak = function(s){ alert(s); } return this.Prototype; } var o = new JSHuman(); o.Set_Name("westfly"); o.Speak(o.Get_Name()); [Ctrl A Select all Note:
]
(Bencalie’s post)
stroll, I am very satisfied with your answer.
You raised the question again, so here Base.call(this, v_sName) is used as Base.apply(this), how do I pass v_sName to Base.BaseName, but I am a little bit confused about the use of apply. It’s hard to understand.
Finally, Base.apply(this, [v_sName]) was used to pass the array successfully
So it looks like call and apply are just different parameters? [Ctrl A Select all Note:
If you need to introduce external Js needs to be refreshed to execute
]
[Ctrl A to select all Note: If you need to introduce external Js, you need to refresh to execute ]
(stroll的跟贴)
To bencalie ,是的,的确仅仅如此
不过不要认为apply这样是麻烦,其实如果两个对象的构造参数顺序一样的话,可以这么来
Base.apply(this, arguments) 很方便吧?
附上:(因为30秒才一贴~~)
不过你那里添加一个 new Base() 是认为无法继承的做法,其实是可以继承方法的,O.BaseMethod() 的调用就是了 ^_^
to:bencalie(Roman的跟贴)
基对象的方法被overwrite了.为什么stroll说 var o = new JSHuman(); o 这个实例是无法访问 JSHuman 的成员的
請看如下代碼:
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
stroll,方法的確繼承過來了,但我在Son對象的搆造函數裏重寫了BaseMethod()
事實上O.BaseMethod()這樣調用已經不是Base對象的BaseMethod()方法了,而是Son對象的BaseMethod()方法,所以我把Base的一個實例儅作Son的成員base,使用
Son實例.base.BaseMethod()
的格式來引用Base的BaseMethod()方法
另外,我喜懽這句:Base.apply(this, arguments)
呵呵……收到~~(stroll的跟贴)
虽然说JS是没有指针了…… 不知道同时构造一个“父对象”,一个“子对象” 再有一个函数传递一个对象参数,这个参数使用父子共有的方法,是不是能够分别调用相应的方法呢? 还未了解JS 的 this 是不是相当于 虚拟地址的指针呢?
所以替换了方法才能解决上面的疑惑(虽然这个迷惑是菜了点,不过符合逻辑:)
还有……如果里面成员有构造对象的函式,是不是也会像c++一样先构造对象,然后再执行其他函式呢? 这个可能或则肯定是按照从上到下了~~~~语言规定?没试过
有没有试过多个父对象的继承呢?不过也不难想到这个一步……(树状继承)
这些就是偶的疑问啦,呵呵……

Detailed explanation of JavaScript string replacement method and FAQ This article will explore two ways to replace string characters in JavaScript: internal JavaScript code and internal HTML for web pages. Replace string inside JavaScript code The most direct way is to use the replace() method: str = str.replace("find","replace"); This method replaces only the first match. To replace all matches, use a regular expression and add the global flag g: str = str.replace(/fi

This tutorial shows you how to integrate a custom Google Search API into your blog or website, offering a more refined search experience than standard WordPress theme search functions. It's surprisingly easy! You'll be able to restrict searches to y

So here you are, ready to learn all about this thing called AJAX. But, what exactly is it? The term AJAX refers to a loose grouping of technologies that are used to create dynamic, interactive web content. The term AJAX, originally coined by Jesse J

This article series was rewritten in mid 2017 with up-to-date information and fresh examples. In this JSON example, we will look at how we can store simple values in a file using JSON format. Using the key-value pair notation, we can store any kind

Leverage jQuery for Effortless Web Page Layouts: 8 Essential Plugins jQuery simplifies web page layout significantly. This article highlights eight powerful jQuery plugins that streamline the process, particularly useful for manual website creation

Core points This in JavaScript usually refers to an object that "owns" the method, but it depends on how the function is called. When there is no current object, this refers to the global object. In a web browser, it is represented by window. When calling a function, this maintains the global object; but when calling an object constructor or any of its methods, this refers to an instance of the object. You can change the context of this using methods such as call(), apply(), and bind(). These methods call the function using the given this value and parameters. JavaScript is an excellent programming language. A few years ago, this sentence was

jQuery is a great JavaScript framework. However, as with any library, sometimes it’s necessary to get under the hood to discover what’s going on. Perhaps it’s because you’re tracing a bug or are just curious about how jQuery achieves a particular UI

This post compiles helpful cheat sheets, reference guides, quick recipes, and code snippets for Android, Blackberry, and iPhone app development. No developer should be without them! Touch Gesture Reference Guide (PDF) A valuable resource for desig


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Chinese version
Chinese version, very easy to use

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)
