[英]Is it possible to nest JavaScript objects?
看來這是不可能的。 還有另一種整齊的方法可以做到這一點嗎?
// Our transitions class
function Transitions() {
this.fade = function() {
this.create = function() {
alert('you have arrived at the create method of the fade class');
}
}
}
這個有可能。 您現在使用它的方式。
您可以執行以下操作來調用創建函數:
var x = new Transitions();
// Here .create does not exists
x.fade(); // Here the create function will be generated to the this object
x.create(); // Does alert
但是您可能想要這樣的東西:
function Transitions() {
// Create an object with an sub object
this.fade = {
create : function() {
alert('you have arrived at the create method of the fade class');
}
}
}
var x = Transitions();
x.fade.create(); // Call the sub object
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.