Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7841979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:13:01+00:00 2026-06-02T16:13:01+00:00

I have a simple property on an Ember object that I want to run

  • 0

I have a simple property on an Ember object that I want to run some value checks on before actually setting and triggering/canceling the change. I’m not having much luck finding any code samples or info on this. The pattern I’m used to from other frameworks is to do it within the setter – something like:

Within an Ember Object

propertyName : function(key, value) {
    // Setter
    if (arguments !== 1) {
        if (setCheckHere) {
           return this._super(key, value); // ??  is this right?
        } 
        // ?? if ignoring what should I return instead?
    }
}.property()

I’m having trouble figuring out what methods I should be calling and what needs to be returned.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T16:13:02+00:00Added an answer on June 2, 2026 at 4:13 pm

    My proposal would be the following, see http://jsfiddle.net/pangratz666/NUTAz/:

    Ember.Object.create({
        _foo: undefined,
        foo: function(key, value) {
            // david
            if (arguments.length === 1) {
                return this._foo;
            }
    
            // setter
            if (value === 42) {
                // set the value because it's cool
                this._foo = value;
            }
    
            // allow chaining, so this.set('foo', 12).set('name', 'Fünke');
            return this;
        }.property()
    });
    

    UPDATE

    A even better solution would be to use a closure as @mraken suggests, see http://jsfiddle.net/pangratz666/Zacfh/:

    Ember.Object.create({
        foo: (function() {
            var _foo;
            return function(key, value) {
                // david
                if (arguments.length === 1) {
                    return _foo;
                }
    
                // setter
                if (value === 42) {
                    _foo = value;
                }
    
                return this;
            }.property();
        })()
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple Windows Form that hosts property controls at runtime. When the
I have some very simple XML: <properties> <property> <name>BobFish</name> <explaination>Bob is a fish.</explaination> </property>
I have simple DAL that consists of a SalesEnquiry object, which includes a List<T>
I have a simple key-value property file where I need to parse a value
I have an object with a simple property: public class obj { /* ...
I have a simple class that has a property called executor in which I'd
I have some data from a 3rd party that includes some string Language property
I have a simple property on my view model that is of type string.
We have a simple method that gets all of a specific domain object where
I have a simple log4j.property file and a simple program that use log4j. But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.